Selenium 2 Webdriver (Unable to find elemeny by xpath)
Can someone tell me what I'm doing wrong? I've tried using Firebug's long-form of the xpath and I ge开发者_C百科t the same error. Using the xpath
//span[@onclick=\"mainIframeSrc('l_sams_sched.p_group_schedule')
I'm able to locate the element and click on "Schedule Entry
" in Selenium IDE. The problem is when I try to do the same using webdriver in IE.
HTML snippet:
<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 code:
driver.findElement(By.xpath("//span[@onclick=\"mainIframeSrc('l_sams_sched.p_group_schedule')\"]")).click();
Error:
org.openqa.selenium.NoSuchElementException: Unable to find element by xpath using "//span[@onclick="mainIframeSrc('l_sams_sched.p_group_schedule')"]" (7) System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_19' Driver info: driver.version: ie at org.openqa.selenium.ie.ErrorHandler.verifyErrorCode(ErrorHandler.java:36) at org.openqa.selenium.ie.Finder.handleErrorCode(Finder.java:219) at org.openqa.selenium.ie.Finder.findElementByXPath(Finder.java:183) at org.openqa.selenium.By$6.findElement(By.java:205) at org.openqa.selenium.ie.Finder.findElement(Finder.java:207) at org.openqa.selenium.ie.InternetExplorerDriver.findElement(InternetExplorerDriver.java:322) at com.eviltester.seleniumtutorials.SAMSLogin.firstPageContainsQAANet(SAMSLogin.java:105) at com.eviltester.seleniumtutorials.SAMSLogin.main(SAMSLogin.java:22) Test failed.
Try this,
WebElement element = driver.findElement(By.cssSelector("div.node>span.node-text"));
element.click();
Do you have in your page an element with id="tags" before the element you try to access in MSIE ? If yes, you have to rename it - see http://code.google.com/p/selenium/issues/detail?id=1500 fro more.
Ahh, and one more possible cause is the security setting - see http://code.google.com/p/selenium/wiki/InternetExplorerDriver - look for "Required Configuration".
精彩评论