XPath is a very useful tool for all of your Selenium tests. It allows you to navigate through multiple elements in the DOM and extract values from them. XPath is a very powerful tool that can be used for any kind of automation project. The primary application of XPath is to locate elements and then examine their attributes. It can also be used to test whether an element has a certain attribute or not.
Implementation of Xpath in Selenium
It is to identify the elements with tag names
It is of two types
1)relative x path
2) Absolute x path
1) Relative x path:-
we can identify the elements with the help of a parent tag and with unique attributes.
In attributes, we can provide multiple also to identify the element.
//input [@id=’f-id’ and @name=’name’]
Interested in mastering Selenium Training? Enroll now for FREE demo on Selenium Training.
2) Absolute XPath:
By using relative XPath if we are unable to identify the element then we can go the absolute path
It will identify the element with the complete hierarchal XML path of the element.
we can take the absolute XPath from the tool fire path. It is an add-on for Firebug.
Launch Firefox and open the below URL
Go to the above path click on “add to Firefox”
How to capture XPath:-
Right-click on the element click on inspect else with firebug and then click on the tagitive element and then click on inspect in the fire path
By default, it generates a relative x path
To get the absolute XPath àclick on the arrow mark at fire pathàselect general XPath
Done firebug and capture the XPath again to get the absolute XPath
Note:-XPath should always start with “//”(or)”xpath=”
Learn more about Selenium Interview Questions in this blog post.
DOM(document object model):-
It will identify the elements based on the form name.
For a piece of in-depth knowledge of Selenium, click on below
- Io streams /external files in Selenium
- Selenium Grid
- Conditional statements in Selenium
- Different flavors of Selenium
- Selenium WebDriver Features