selenium - 无法使用操作拖动元素
问题描述
网址 - http://www.seleniumeasy.com/test/drag-and-drop-demo.html
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"//drivers//chrome//chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebElement itemToBeDragged=driver.findElement(By.xpath(" (//h3[contains(.,'Items to Drag')]//following-sibling::span)[1]"));
WebElement
whereToBeDragged=driver.findElement(By.xpath("//div[@id='mydropzone']"));
Actions action=new Actions(driver);
Action dragAndDrop = action.clickAndHold(itemToBeDragged).moveToElement(whereToBeDragged).release(whereToBeDragged).build();
dragAndDrop.perform();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.close();
使用上面的代码我无法拖放元素。请帮忙 !
解决方案
您可以尝试使用生成器吗
实现这个方法
public static void dragAndDrop(WebElement fromWebElement, WebElement toWebElement) {
Actions builder = new Actions(driver);
builder.dragAndDrop(fromWebElement, toWebElement);
}
推荐阅读
- python - SQL 一对多关系 - 以 JSON 格式检索数据的查询
- r - 根据条件复杂的另一行调整数据框行
- node.js - 我对 react.js 中的 state.map 有问题,没有显示数据
- android - 在颤振飞镖中,我必须为包和应用程序 ID 添加相同的名称
- mysql - 查询根据条件返回值
- mysql - JSON_Extract 错误:函数 json_extract 的参数 1 中的 JSON 文本无效:“缺少对象成员的名称。”
- javascript - 为什么我的滚动顶部功能会根据我的位置滚动到页面的不同部分,仅在移动设备上?
- spring-boot - 在客户端通过 STOMP 发送大消息失败
- sql - 如何在sql server中处理多值属性
- arduino - 如果 x 秒内没有串行数据,则关闭模拟引脚