Selenium 4 - Relative Locator - Codoid
Select Page
Codoid Blog

Selenium 4 – Relative Locator

Irrespective of the business that your client is in, marketing is an integral part of their operations. In fact, in this day and age of social.

As an automation testing company, we intent to explore new automation testing tools and its features in our Automation CoE’s R&D Workshop. Today, we would like to share one of the salient features of Selenium 4. Selenium 4 Alpha-3 has released a new feature for finding web elements using Relative Locator. It has the following methods – ‘withTagName’, ‘above’, ‘below’, ‘toLeftOf’, ‘toRightOf’, and ‘near’.

Relative Locator Benefits

1) Using ‘near’ method, you can find element with pixel distance.

2) In responsive testing, you can check whether the web elements are rendered in the expected order.

Snippet

driver.get("http://codoid.com");
driver.findElement(withTagName("p").near(By.className("cls1"),120));
  

Conclusion

If you are familiar with XPath Axes and CSS Selector, then Relative Locator does not add any value. However, it is too early to comment on this feature. Let’s wait for others’ opinion as well.

Written By

Submit a Comment

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


As an automation testing company, we intent to explore new automation testing tools and its features in our Automation CoE’s R&D Workshop. Today, we would like to share one of the salient features of Selenium 4. Selenium 4 Alpha-3 has released a new feature for finding web elements using Relative Locator. It has the following methods – ‘withTagName’, ‘above’, ‘below’, ‘toLeftOf’, ‘toRightOf’, and ‘near’.

Relative Locator Benefits

1) Using ‘near’ method, you can find element with pixel distance.

2) In responsive testing, you can check whether the web elements are rendered in the expected order.

Snippet

driver.get("http://codoid.com");
driver.findElement(withTagName("p").near(By.className("cls1"),120));
  

Conclusion

If you are familiar with XPath Axes and CSS Selector, then Relative Locator does not add any value. However, it is too early to comment on this feature. Let’s wait for others’ opinion as well.