XPathPPT Mahendra

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Topic: XPATH

by- Mahendra
 Xpath is Locator:
o Locators are used to identify web element on the UI Page.

o Elements: each component on UI is web element like button, text,


link, radio button, dropdown etc.

 8 Locators in Selenium:
What is XPATH ?  Selenium has 8 locators namely, ID, Name, xpath, cssSelector,
linkText, PartialLinkText,TagName, ClassName

 Xpath vs Other Locators:


 Uniquely Identify, Can Travel in Node Parent to child, child to
parent, has defferents methods like contains, text(), starts with,
axes methods etc, conditioning locator OR , AND

2
What Are The Types Of
Xpath?
◦ It Starts with / single slash
◦ Locates The Element from Root
Element
Absolute
◦ Long, Timing consuming, complex,
Xpath
error prone
◦ /html[1]/body[1]/div[1]/div[2]/div[1]/
img[1]

4
◦ It Starts with // double slash
◦ Directly refer to element
Relative Xpath ◦ Small in size as compared to Absolute
xpath

5

◦ How to write a Xpath
Expression ?

6
◦ Basic Expression: XPath =//tagname[@Attribute=’Value’]

◦ Dynamic Expression: //tagname[contains(@attribute,constantvalue)]

◦ Conditional Operators: XPath=//tagname[@attribute1=value1 OR @attribute2=value1]

◦ Xpath Text Operator: //tagname[text()=’Text of the Web Element’] / //tagname[starts-


with(@attribute,value)]

◦ Chained Xpath: //tagname1[@attribute1=value1]//tagname2[@attribute2=value2]

7
What are Xpath axes?
Following: This indicates all the nodes that appear after the context node in the HTML DOM structure.
Following-sibling: This one indicates all the sibling nodes (same parent as context node)
that appear after the context node in the HTML DOM structure.
Preceding: This indicates all the nodes that appear before the context node in the HTML DOM structure.
Preceding-sibling: This one indicates all the sibling nodes (same parent as context node) that
appear before the context node in the HTML DOM structure.
Child: This indicates the children of the context node.
Parent: This indicates the parent of the context node.
descendant: This indicates the children, and grandchildren and their children (if any) of the context node.
Ancestor: This axes indicates all the ancestors relative to the context node, also reaching up to the root
node.

You might also like