繁体   English   中英

Selenium 2 Webdriver(无法通过xpath找到elemeny)

[英]Selenium 2 Webdriver (Unable to find elemeny by xpath)

有人能告诉我我做错了什么吗? 我尝试过使用Firebug的长路径xpath,我得到了同样的错误。 使用xpath

//span[@onclick=\"mainIframeSrc('l_sams_sched.p_group_schedule')

我能够找到该元素并单击Selenium IDE中的“ Schedule Entry ”。 问题是我尝试在IE中使用webdriver做同样的事情。

HTML片段:

<div class="node">
<img alt="Schedule Entry" src="/csui/leaf.gif">
<span class="node-text" onmouseout="this.className='node-text'" onmouseover="this.className='node-text-over'" onclick="mainIframeSrc('l_sams_sched.p_group_schedule')">Schedule Entry</span>
</div>

Webdriver代码:

driver.findElement(By.xpath("//span[@onclick=\"mainIframeSrc('l_sams_sched.p_group_schedule')\"]")).click();

错误:

org.openqa.selenium.NoSuchElementException:无法通过xpath使用“//span[@onclick="mainIframeSrc('l_sams_sched.p_group_schedule')”找到元素“”“(7)系统信息:os.name:'Windows XP', os.arch:'x86',os.version:'5.1',java.version:'1.6.0_19'驱动程序信息:driver.version:即org.openqa.selenium.ie.ErrorHandler.verifyErrorCode(ErrorHandler.java: 36)org.openqa.selenium.ie.Finder.handleErrorCode(Finder.java:219)org.openqa.selenium.ie.Finder.findElementByXPath(Finder.java:183)atg.openqa.selenium.By $ 6。 findElement(By.java:205)atg.openqa.selenium.ie.Finder.findElement(Finder.java:207)at com.viltester的org.openqa.selenium.ie.InternetExplorerDriver.findElement(InternetExplorerDriver.java:322) .seleniumtutorials.SAMSLogin.firstPageContainsQAANet(SAMSLogin.java:105)at com.eviltester.seleniumtutorials.SAMSLogin.main(SAMSLogin.java:22)测试失败。

尝试这个,

WebElement element = driver.findElement(By.cssSelector("div.node>span.node-text"));
element.click();

在您尝试在MSIE中访问的元素之前,您的页面中是否有id =“tags”的元素? 如果是,则必须重命名 - 请参阅http://code.google.com/p/selenium/issues/detail?id=1500

啊,还有一个可能的原因是安全设置 - 请参阅http://code.google.com/p/selenium/wiki/InternetExplorerDriver - 查找“必需配置”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM