Software Development and QA Tips By QASource Experts

How To Find the Sibling of an Element Using Selenium?

Written by Timothy Joseph | Aug 30, 2021 4:00:00 PM

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.