I have tested the Gmail login page and was trying to verify the Sign in label in the Gmail login page above the user name field. I am using FirePath to generate the Xpath. When I inspect the element Sign in using Firebug, FirePath generated the absolute Xpath html/body/div[1]/div[2]/div[1]/div/h2. When I copy this Xpath and execute it, the testcase fails. Adding // to the absolute Xpath works, i.e. //html/body/div[1]/div[2]/div[1]/div/h2. To summarize, the absolute Xpath works with / (single slash) whereas relative Xpath works with //. Can anyone correct my mistakes or explain this?
|
|
||||
|
|
|
You mentioned three ways to start an Xpath. If you have not read the sections of the W3C Xpath specification on locations and abbreviations, you may benefit from doing so. It is not very long. |
||||
|
|
From my experience, sometimes the way XPaths are read by Selenium are different from what you expect, especially if you've verified the XPaths are correct in Firepath. Yes, both of the XPaths you've posted point to the same element and should work identically, but for some reason, only the relative one is working correctly in the IDE. The main takeaway from this is to avoid absolute XPaths like the plague! Always use relative ones, but make them more specific, so other elements aren't found instead (since Selenium picks the first out of all the matches). This is nice and short: If you want to be more precise, try: I tested each of the above with Firepath and Selenium IDE and they work. |
|||
|
|
|
I would suggest never use complete xpath in any UI test. And the reason is if anything gets change in the UI structure then your test will fail. And there will be huge cost towards maintaining your test cases. So for any UI test we should try to identify elements based on their unique id/class/div name etc. For your case to find out sign in link you can use the following command:
Hope this will help you. |
||||
|
|