The hidden classes no one knows about which help you locate the elements in Selenium.

Abhishek Dhoundiyal
Apr 7, 2021 · 2 min read

There are 3 Selenium classes that are not so popular and so many people even hadn’t heard about them. These classes can come in handy in our day to day tasks.

These three gems are:
- ByAll
- ByChained
- ByIdOrName

1) ByAll

Package org.openqa.selenium.support.pagefactory

org.openqa.selenium.support.pagefactory.ByAll

Implementation:

We have to call the constructor:

ByAll​(By… bys)

Arguments: Pass the Multiple locators separated by a comma.

The mechanism used to locate elements within a document using a series of lookups. This class will find all DOM elements that match any of the locators in sequence, e.g.

will find all elements that match by1 and then all elements that match by2. This means that the list of elements returned may not be in document order.

— — — — — — — — — — — — — — — — — — — — — —

2) ByChained

The mechanism used to locate elements within a document using a series of other lookups. This class will find all DOM elements that match each of the locators in sequence, e.g.

Package org.openqa.selenium.support

org.openqa.selenium.support.pagefactory.ByChained

Implementation:

We have to call the constructor:

ByChained​(By… bys)

Arguments: Pass the Multiple locators separated by a comma.

will find all elements that match by2 and appear under an element that matches by1.

Code:

— — — — — — — — — — — — — — — — — — — — — — — — —

3) ByIdOrName

This helps the driver to locate an element either by name or by id.

Package org.openqa.selenium.support

org.openqa.selenium.support.ByIdOrName.ByIdOrName(StringidOrName).

Implementation:

We have to call the constructor:

ByIdOrName​(java.lang.String idOrName).

Arguments: Pass the Name or ID.

This method first tries to find the element using ID and waits for the element to locate and if it is not able to find the element with ID then only it tries to locate with the Name.

Code:

WebDriver.Support (in WebDriver.Support.dll) Version: 3.1.0

Note: Complete explanation will come in the next part.

Geek Culture

Proud to geek out. Follow to join our +1.5M monthly readers.