An Overview of XPath
Posted By : Rahul Jain | 31-Jan-2018
Overview of Xpath:
Xpath is a language for finding an element on the web page using XML path expression. Xpath is used to find the location of the element on a webpage using HTML DOC structure.
Xpath contains the expression, nodes, absolute and relative xpath etc.
Syntax of Xpath:-
1.//: Select the current node.
2.Tag name: Particular tagname of HTML DOM structure.
3.@: Select attribute.
4.Attribute: Attribute name of the particular node.
5.Value: the Particular value of the node.
There are two types of xpath:
1. Absolute xpath
2. Relative xpath
1. Absolute xpath:
It is the direct way to locate the web element but we do not recommend this method because whenever there are any changes made in the path then that xpath gets failed.
2. Relative xpath:
Relative xpath starts with HTML Dom structure.It starts with double slash (//), which means that it can search the element anywhere on the webpage.
There are seven types of Xpath expression.
1. Root
2. Element
3. Text
4. Attribute
5. Comment
6. Processing Instruction
7. Namespace
There are some locator which helps to locate the webelement at the webpage.
ID- We can find the element by the ID.
ClassName- To find the element with the help of className
Name- To find the element by the name.
Xpath- To find the element dynamically and traverse the element from parent to child and vice-versa.
CSS Selector- To find the element by traversing.
linked text-To find the element by text of the link.
PartialLinkedText-To finds the element by the partial text of the link.
What is Xpath Axes:
Axes method are used to find that element which are changed on refresh or perform any other operation.
There are few axes which are used frequently in selenium webdriver like child, parent, ancestor, descendant, sibling.
Methods of xpath:
There is some method to locate the web element at the webpage.
1. Text function
2. Contains Function.
3. Start-with
4. Not contains
5. Following-sibling
6. Preceding-sibling.
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
Rahul Jain
Rahul have good experience in manual and automation testing based on the web based application and expertise to finding the bug and providing the appropriate solution.