Xpath Axes Locators in Selenium WebDriver- Dynamic HTML Table


Refer to the below Links for Practise
Complete JAVA QUIZ
Selenium Advanced Quiz
50 Real Time Interview Questions
Selenium Quiz
REST API QUIZ

Dynamic Content:

In Web Applications the data in the HTML Table is dynamic always.
To Fetch the data available in the Dynamic Table or to identify the
Dynamic Web Elements available in the Web Page we should depend on Xpath Axes Locators.

Following are the Xpath Axes Locators:
Link for XPATH AXES-> https://www.w3schools.com/xml/xpath_axes.asp

ancestor – select parent or grand parent
following-sibling– Which follows
preceding-sibling – Which precedes
descendant – Child/subChild
parent – Select Immediate PArent
child – Select immeidate Child
following – Select all the matching nodes which are following
preceding – Select all the matching nodes which are preceding

Real Time Example:

1. Access the Web Application URL -> https://money.rediff.com/gainers/bse/daily/groupa?src=gain_lose
2. Find the Stock Name ->‘Adani Enterprises Lt’.
3. Get the Price associated with the Stock Name.

Identify the following Xpath in Firepath for understanding:
Xpath Axes Locators
Xpath Example 1:
Identify the Parent of the WebElement
//a[contains(text(),'Adani Enterprises')]/parent::td


Xpath Example 2:
Identify the Ancestor of the Web Element
//a[contains(text(),'Adani Enterprises')]/parent::td


Xpath Example 3:
Identify the following Elements of the Web Element
In the Case of following all the Elements which are matching will be selected. Now the matching nodes are 501.
//a[contains(text(),'Adani Enterprises')]/parent::td/following::td


Xpath Example 4:
Identify the following siblings of the Web Element
In the Case of following-sibling all the Elements which are matching but should be part of the parent tag ‘tr’. Now the matching nodes are 4.
//a[contains(text(),'Adani Enterprises')]/parent::td/following-sibling::td


Fetching the Price associated with the Stock:
//a[contains(text(),'Adani Enterprises')]/parent::td/following-sibling::td[2]


Selenium Program:

Leave a Reply

Your email address will not be published. Required fields are marked *