【发布时间】:2014-12-01 11:35:02
【问题描述】:
代码:
public void Test2() throws Exception{
Thread.sleep(5000);
driver.findElement(By.id("cboMenu")).click();
driver.findElement(By.xpath(".//*[@id='cboMenu/option[3]")).click();
}
错误:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"cboMenu"}
Command duration or timeout: 31 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: 'venu-PC', ip: '192.168.1.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 0f859bed-35df-4eba-a472-3bc2efec4814
Driver info: org.openqa.selenium.firefox.FirefoxDriver
【问题讨论】:
-
您要定位哪个元素?你能提供更多细节吗?
-
public void Test2() throws Exception{ Thread.sleep(5000); driver.findElement(By.id("cboMenu")).click(); driver.findElement(By.xpath(".//*[@id='cboMenu/option[3]")).click();
-
我已经发布了答案,请检查 xpath,如果仍然无法正常工作,那么您能否显示我们试图通过 xpath 检测的元素的 HTML 代码或完整的错误消息
-
能否请您添加相关的html代码sn-p?