【发布时间】:2018-05-23 18:21:28
【问题描述】:
网址 - 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();
使用上面的代码我无法拖放元素。请帮忙!
【问题讨论】:
标签: selenium