How To Find the Sibling of an Element Using Selenium?

Author: Timothy Joseph
Timothy Joseph | August 30, 2021
How To Finding the Sibling of an Element Using Selenium?

In any automation project, it's important to choose the correct locators in order to make your automation framework more efficient. XPath is one of the techniques commonly used in Selenium, which enables easy, efficient and reliable automation. It allows QA engineers to navigate through the XML structure of any document. You can create XPaths specific to the requirement, which is a recommended practice.

The pattern below will allow you to find the date value using "following-sibling parent" relationship.

- //div[text()='(123)']/../following-sibling::div/div

You can also write "following-sibling" locator as:

- //tagname[@attribute='value']//following-sibling::tagname

This will select all nodes that have same parent as current node and also appears after it.

Need more assistance in order to make the most out of the Selenium tool, QASource can help.
Contact QASource today and get professional assistance for using Selenium for test automation.

Disclaimer

This publication is for informational purposes only, and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment