Here we will learn How to handle dynamic xpath in Selenium using Xpath Axes
Xpath locator is use to locate web elements on web pages. It is the path of web element in XML (Extensible Markup Language) file.
Xpath Axes:-
Xpath axes is use to search different nodes from current node in XML file. Mainly Xpath axes is use to handle the dynamic web elements. Some web element's xpath dynamically change on refresh or any other operation. There are few axes methods used in selenium webdriver child, parent, following, follower, ancestor,sibling and preceding etc.
See below which are commonly used in selenium:
Examples:
Child Axes: It defines the children of the current node.
Xpath: //div[@id='irfooterlogo']//child::li
Parent Axes: It defines the parent of the current node.
Xpath: //input[@name='j_captcha']//parent::*
Following Axes: It defines all nodes after current node in same document order.
Xpath: //input[@name='j_username']//following::*
Following-Sibling Axes: It defines all sibling after current node.
Xpath: //input[@name='uri']//following-sibling::input[2]
Preceding Axes: It defines all node before current node in same document order.
Xpath: //a[text()='How to select a value from dropdown']//preceding::li[1]
Preceding-Sibling Axes: It defines all sibling node before current node.
Xpath: //input[@type='submit']//preceding-sibling::input[2]
Ancestor Axes: It defines all parents node of current node.
Xpath: //input[@type='submit']//ancestor::tbody[1]
Descendant Axes: It defines all children (Also children of the child node's current node)of the curent node.
Xpath: //div[@id='irfooterlogo']//descendant::li[1]
Hope you have learnt well. If there is any confusion, please comment me !!
Xpath locator is use to locate web elements on web pages. It is the path of web element in XML (Extensible Markup Language) file.
Xpath Axes:-
Xpath axes is use to search different nodes from current node in XML file. Mainly Xpath axes is use to handle the dynamic web elements. Some web element's xpath dynamically change on refresh or any other operation. There are few axes methods used in selenium webdriver child, parent, following, follower, ancestor,sibling and preceding etc.
See below which are commonly used in selenium:
Examples:
Child Axes: It defines the children of the current node.
Xpath: //div[@id='irfooterlogo']//child::li
Parent Axes: It defines the parent of the current node.
Xpath: //input[@name='j_captcha']//parent::*
Following Axes: It defines all nodes after current node in same document order.
Xpath: //input[@name='j_username']//following::*
Following-Sibling Axes: It defines all sibling after current node.
Xpath: //input[@name='uri']//following-sibling::input[2]
Preceding Axes: It defines all node before current node in same document order.
Xpath: //a[text()='How to select a value from dropdown']//preceding::li[1]
Preceding-Sibling Axes: It defines all sibling node before current node.
Xpath: //input[@type='submit']//preceding-sibling::input[2]
Ancestor Axes: It defines all parents node of current node.
Xpath: //input[@type='submit']//ancestor::tbody[1]
Descendant Axes: It defines all children (Also children of the child node's current node)of the curent node.
Xpath: //div[@id='irfooterlogo']//descendant::li[1]
Hope you have learnt well. If there is any confusion, please comment me !!
No comments:
Post a Comment