我无法使用Chrome浏览器中的selenium webdriver处理拖放功能。
这是我的代码:
WebDriver driver=new ChromeDriver();
String URL = "http://www.dhtmlx.com/docs/products/dhtmlxTree/index.shtml";
driver.get(URL);
// It is always advisable to Maximize the window before performing DragNDrop action
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
WebElement From = driver.findElement(By.xpath(".//*[@id='treebox1']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));
From.click();
WebElement To = driver.findElement(By.xpath(".//*[@id='treebox2']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));
To.click();
Actions builder = new Actions(driver);
System.out.println("builder:"+builder);
Action dragAndDrop = builder.clickAndHold(From).moveToElement(To).release(To).build();
System.out.println("draganddro:"+dragAndDrop);
dragAndDrop.perform();
答案 0 :(得分:0)
尝试以下代码..它会起作用..
public void mouseOverDrag1(final WebDriver driver, By mainMenu, By subMenu) throws Exception{
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(mainMenu);
WebElement subHoverLink = driver.findElement(subMenu);
System.out.println(menuHoverLink.getText());
actions.clickAndHold(menuHoverLink);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
actions.moveToElement(subHoverLink).release(subHoverLink).build();
actions.perform();
}