The Significance of Using Xpath In QA Testing
Posted By : Pooja Kumari | 26-May-2020
Xpath is the syntax or language to find an element on the web page. In this blog post, we'll explore the significance of using Xpath in QA testing.
Finding an element is one of the most difficult parts. If you are not able to find the elements by the easily available approaches like ID, CLASS, NAME, LINK, and TAGNAME, then Xpth is one of the best methods to rescue you from this problem in selenium. We can say that Xpath is the syntax or language to find an element on the web page.
Standard syntax of creating Xpath is given below:
Xpath=//tagname[@Attribute=’Value’]
Where:
- // :Select current node.
- Tagname: Tagname of the particular node.
- @ :Select attribute.
- Attribute: Attribute name of the node.
- Value: Value of the attribute.
Types of X-path
1. Absolute Xpath
2. Relative Xpath
Absolute Xpath
In case of an absolute Xpath, it starts with a single '/ ', which means you can select the element from the root node. One of the biggest disadvantages of using that is, whenever during the development period, any changes will be made in the Xpath then, Xpath will become invalid which leads to script failure.
For example:
/html/body/div[1]/section/div/div[2]/div/form/div[2]/input[3]
In the above example in selenium, if any of the tag names like section or any of the division changes then, Xpath will become invalid and it will lead to script failure.
Relative Xpath
In the case of relative Xpath, It starts with a double forward-slash(//), it means, it can search the elements anywhere on the webpage.
For example:
//input[@name=’email’]
In the above example in Selenium, we are searching from the current node with tag name input having attribute as the name with value as email.
Xpath Function
In some cases, when the elements having the same attributes, names, or having more than one button with the same name and same Id's, then it becomes challenging to identify the particular object on the web page using selenium, then Xpath function comes to solve this problem.
Types of Xpath functions are:
1. contains()
2. starts-with()
3. text()
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Pooja Kumari
Pooja is QA engineer . She has knowledge of manual testing and SQL. And keen to learn new things.