我正在做一个可以执行拖放操作的测试。
我目前的代码:
WebElement element;
By mainSelector, secondarySelector;
Actions action;
action = new Actions(driver);
mainSelector = By.cssSelector("tbody.naam tr:nth-child(1) td:nth-child(1)");
secondarySelector = By.cssSelector("tbody.bedrijf tr:nth-child(1) td:nth-child(1)");
action.click(driver.findElement(mainSelector));
action.clickAndHold(driver.findElement(mainSelector))
.moveToElement(driver.findElement(secondarySelector), 5, 5)
.perform();
action.release(driver.findElement(secondarySelector));
action.perform();
action.dragAndDropBy(driver.findElement(mainSelector), 300, 300).perform();
action.dragAndDrop(driver.findElement(mainSelector), driver.findElement(secondarySelector)).perform();但是这并不能做任何事情。我已经添加了多个性能,因此请确保这不是问题所在。我添加了一个偏移量,因为我读到这有时是错误的。我使用firefox进行测试。
发布于 2014-12-08 17:21:34
如果想要将mainSelector拖到secondarySelector中,可以执行以下操作
Method 1
mainSelector = driver.findElement(By.cssSelector("tbody.naam tr:nth-child(1) td:nth-child(1)"));
secondarySelector = driver.findElement(By.cssSelector("tbody.bedrijf tr:nth-child(1) td:nth-child(1)"));
action = new Actions(driver)
action.dragAndDrop(mainSelector, secondarySelector).perform();Method 2
action.clickAndHold(mainSelector).moveToElement(secondarySelector).release().build().perform();这两种方法都可以完成任务。
希望它能有所帮助!:)
https://stackoverflow.com/questions/27354460
复制相似问题