【发布时间】:2016-11-11 17:55:46
【问题描述】:
下面的代码用于使用WebDriver 测试拖放功能。我在代码中遇到的问题是它无法检测到 XPath。
public class draganddrop
{
public static void main(String[] args) throws InterruptedException
{
// opening site for practicing user interaction by mouse using webdriver and action class
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"));
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"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From).moveToElement(To).release(To).build();
dragAndDrop.perform();
Thread.sleep(2000);
}
}
错误信息
线程 "main" org.openqa.selenium.NoSuchElementException 中的异常:没有这样的元素:无法找到元素:{"method":"xpath","selector":".//*[@id='treebox1 ']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"}
【问题讨论】: