Usage of Single ‘/’ and double ‘//’ in the xpath And Absolute Xpath & Relative Xpath
A single slash at the start of Xpath instructs XPath engine to look for element starting from root node.
A 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:
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:
- Navigate to the page I want to verify
- Press F12 to bring up Chrome debugger
- Press ctrl + f to bring up find
- Type or paste in the xpath expression that I want to test
- See if the xpath found an element. OR
- Open Developer Tools
- Select Console tab.
- Use
$x
token. For example,$x("/html/body")
will select thebody
tag. Internet Explorer: he 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