【发布时间】:2016-06-25 03:59:21
【问题描述】:
我指的是http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick_copy。单击按钮时,应该将 field1 中的值复制到 field2。我试图用 selenium webdriver 自动化它。
我正在使用WebDriver 命令作为:
driver.get("http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick_copy");
driver.findElement(By.xpath(".//button[@onclick='myFunction()']")).click();
但我得到了错误:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//button[@onclick='myFunction()']"}
Command duration or timeout: 20.11 seconds
之后我尝试了:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById(\"field2\").value = document.getElementById(\"field1\").value;");
这次我得到了错误:
org.openqa.selenium.WebDriverException: document.getElementById(...) is null
【问题讨论】:
-
感谢 JeffC 格式化问题
标签: javascript java selenium