Selenium With Java and Python For Mobile Apps & Web Apps......!

Wednesday, 31 December 2014

Usage of Single ‘/’ and double ‘//’ in the xpath And Absolute Xpath & Relative Xpath

single slash at the start of Xpath instructs XPath engine to look for element starting from root node.
double slash at the start of Xpath instructs XPath engine to search look for matching elementanywhere in the XML document.
Absolute XPath: The easiest way of finding the xpath is to use the Browser Inspector tool to locate an element and  get the xpath of it:
XPath Generated by the tool is : /html/body/div[2]/div/div/footer/section[3]/div/ul/li[3]/a
Relative XPath: At times XPath generated by Firebug are too lengthy and you see there is a possibility of getting a shorter XPath. Above xpath will technically work, but each of those nested relationships will need to be present 100% of the time, or the locator will not function.  Above choosed xpath is known as Absolute xpath. There is a good chance that your xpath will vary in every release. It is always better to choose Relative xpath, as it helps us to reduce the chance of element not found exception.

How To Get Xpath In Different-2 Browser?
Mozilla FireFox: Used FireBug and FirePath plugins for Mozilla link:
http://getfirebug.com/
https://addons.mozilla.org/en-US/firefox/addon/firepath/
Chrome:Here is the steps to do so:

  1. Navigate to the page I want to verify
  2. Press F12 to bring up Chrome debugger
  3. Press ctrl + f to bring up find
  4. Type or paste in the xpath expression that I want to test
  5. See if the xpath found an element.                                                                                                           OR
  1. Open Developer Tools
  2. Select Console tab.
  3. Use $x token. For example, $x("/html/body") will select the body tag.                                                                                                                                                                                                            Internet Explorerhe tool is the Internet Explorer developer bar. What it does show you is the tree (xpath) for the element you click on when you turn the “select element by click” option.                         

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews