Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

xpath determines differently in Selenium 1 and Selenium 2 #2001

Closed
lukeis opened this issue Mar 2, 2016 · 8 comments
Closed

xpath determines differently in Selenium 1 and Selenium 2 #2001

lukeis opened this issue Mar 2, 2016 · 8 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 2001

Selenium version : 1.0.3 ; version: '2.0rc3', revision: '12536'
OS : windows 7
Browser : FireFox 
Brower version : 3.6.16
I tried to click the same element with selenium 1 and with selenium 2.
In selenium 1 this code works good, element determined by xpath :

selenium = new DefaultSelenium("localhost", 4444, BROWSER, START_URL);
selenium.start();
...
selenium.click("//tbody[@id='tableBody']/tr[1]/td[3]");

In selenuim 2 i try this :

WebDriver driver=new FirefoxDriver();
Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl);
...
selenium.click("//tbody[@id='tableBody']/tr[1]/td[3]");

and get 
com.thoughtworks.selenium.SeleniumException: Element //tbody[@id='tableBody']/tr[1]/td[3]
not found

What is the problem?

Reported by kasheylm on 2011-07-07 12:59:22

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

if the element is added to the page by javascript code, it could be that it's simply
not there yet when you run the search (this is a common case for GWT applications,
which dynamically modify the page after it's loaded).
Please provide a test case if using WebDriverWait does not help.

Reported by eran.mes on 2011-07-13 14:31:36

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

The problem was that this element contain's in iframe. When I used selenium 1 it work
without forse selecting this frame. But when I use selenium 2 webdriver it needs to
select that iframe first and than click element.

So, the problem in different determining in selenium 1 and 2.

P. S. : the timeouts were used.

Reported by kasheylm on 2011-07-18 13:19:59

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have run into a similar issue, only in my case it is not related to performing a click
using Xpath, but rather a getText.  

Selenium 1/RC seems to go through all frames (some are even frames nested in frames)
when using XPath; while Selenium 2 WebDriver does not.  

Is this potentially a "bug" in how the WebDriver works or is this just a functional
difference that I'll need to work through.

Reported by brian.burress on 2011-08-18 20:24:24

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Additional info.  I am attaching the jsp source files for the sample page I have created
to assist me with trying to work through a solution.

Basically, a page with three iframes 1, 2, 3 where frame 3 is embedded in frame 1.

Under RC these statements work fine and pull the expected text (Special Request$xxx,xxx)..Note,
I made a distinction Selenium 1/RC above and I am really running the RC included with
the Selenium 2 jars.  I guess this is still considered 1?

selenium.getText("//div[contains(@id,'frame1')]");
selenium.getText("//div[contains(@id,'frame2')]");
selenium.getText("//div[contains(@id,'frame3')]");

where as similar statements under web driver fail
driver.findElement(By.xpath("//div[contains(@id,'frame1')]"));
driver.findElement(By.xpath("//div[contains(@id,'frame3')]"));

org.openqa.selenium.NoSuchElementException: Unable to locate a node using //div[contains(@id,'frame1')]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.4.0', revision: '13337', time: '2011-08-12 09:58:05'

Reported by brian.burress on 2011-08-18 20:47:56


- _Attachment: [xpathIframe.jsp](https://storage.googleapis.com/google-code-attachments/selenium/issue-2001/comment-4/xpathIframe.jsp)_ - _Attachment: [iframe1.jsp](https://storage.googleapis.com/google-code-attachments/selenium/issue-2001/comment-4/iframe1.jsp)_ - _Attachment: [iframe2.jsp](https://storage.googleapis.com/google-code-attachments/selenium/issue-2001/comment-4/iframe2.jsp)_ - _Attachment: [iframe3.jsp](https://storage.googleapis.com/google-code-attachments/selenium/issue-2001/comment-4/iframe3.jsp)_

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by barancev on 2011-10-13 06:14:01

  • Labels added: Component-WebDriver

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I have recorded the script using IDE and ExportedAs Junit4(Webdriver),Junit(Backed Selenium).
While observing from both exported test cases webdriver unable to find the frames.
My problem is the script working fine while play it by using IDE but its getting failed
while executing the exported script. Please help me to solve the issue.

//--Unable to find this below frames 
selenium.selectFrame("relative=up"); 
selenium.selectFrame("PWGadget1Ifr"); 

Thanks & Regards,
Sreenu..

Reported by sreenu.lekkala on 2012-02-22 03:42:40

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I'm not sure about RC, but in WebDriver you have to switch to a frame (or an iframe)
explicitly.

I'm closing this as 'Working as intended'. Please feel free to reopen if it is still
an issue.

Reported by barancev on 2012-06-01 20:37:28

  • Status changed: WorkingAsIntended

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:13:10

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 2, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant