You’ll need to show us the XML.
My initial observation is that you are starting the Selenium xpath with // and the WebDriver one with / which could be why the WebDriver one is failing (that being said <html> is normally a root element so I would expect it to work assuming this is xhtml).
Secondly as peter mentions this is a very brittle XPath if you are testing a website, if you are testing an XML file which has been properly defined this is the recommended way to use XPath. I’m guessing you are actually using xhtml though.
@Peter
Those are XML namespaces, they are not usually used in web pages, the default namespace is an empty string which is what is normally used by everybody. Multiple namespaces can become a real pain in the arse (in my opinion from a testing point of view), especially when you don’t know in advance what all the namespaces are going to be.
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Hari
Sent: 08 July 2012 09:44
To: seleniu...@googlegroups.com
Subject: [selenium-users] Webdriver xpath is not working
Hi,
--
You are missing the line(s) above the <html> element where the namespace would be defined.
If the page previously had namespaces and now no longer has then that would cause your xpath to break, but I would expect it to break across the board if this was the case.
Secondly, the <head> tag is not closed so body is now a child of head, not of html (this will break your xpath)
The rest look slike it should work.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/33EXyZzRRYoJ.
The html you have provided is a series of frames, are you switching to the correct frame before performing the findElement?
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Hari
Sent: 09 July 2012 10:37
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Re: Webdriver xpath is not working
Hi
Just before the line below can you add the following:
String htmlSource = driver.getPageSource();
System.out.println(htmlSource);
And show us what is printed in the console.
That has returned a frameset page so the reason you are getting your error is because you have not switched to the frame that holds the table, hence Selenium cannot see the table.
Step through your code in a debugger to work out why the frame switch isn’t happening.
--
Not if his HTML is using namespaces he shouldn’t. The x: part is perfectly valid if there is an x namespace configured.
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Ripon Al Wasim
Sent: 09 July 2012 12:04
To: seleniu...@googlegroups.com
No idea I haven’t seen your full Selenium RC code and your full WebDriver code so that I can compare them. The translation to WebDriver may not have gone as intended…
Firebug will automatically select the frame that holds the element that you examined. To the left of the XPath box there is a frame drop down that will let you select the other frames. If you select the parent frameset this XPath will no longer work.
Firebug is no doubt giving you a correct XPath for that frame, but you still haven’t selected the frame in your selenium test.
I would guess that Selenium RC may be performing some implicit frame selection for a frameset (I remember intermittent errors with Selenium RC and frames from many moons ago) that WebDriver does not. If this is the case you got lucky with the Selenium RC API (I would have also expected intermittent failures from that test), now you need to write the test properly when using the WebDriver API.
At the end of the day, you haven’t selected the frame, the fix is to select it.
Yes you need to switch to the frame:
WebElement theFrame = driver.findElement(By.id("<ID Of Correct Frame>"));
driver.switchTo().frame(theFrame);
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b7dec0bb-3878-44d6-b4de-45f9d8f732b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CADrmqWXmrPKf_3Ys5y1f-WDQHiXmiCgzCRJ3_iPqOB%2BwdP-w9w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAEvVa0MWBNbsvDSEivrWJRg%2BoFRN9pzi4zN%3Dvhge9vbx78LQhg%40mail.gmail.com.