How to Find more than One Web Elements in the List

0
925

At times, we may come across elements of same type like multiple hyperlinks, images, etc. arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.

Below is sample code written for the same:

[java]

// Storing the list

List elementList = driver.findElements(By.xpath(“//myxpath”));

// Fetching the size of the list
int listSize = elementList.size();

for (int i=0; i<listSize; i++)
{
// Clicking on each service provider link
serviceProviderLinks.get(i).click();
// Navigating back to the previous page that stores link to service providers
driver.navigate().back();
}

[/java]

The above written code is the basic code . You can enhance it as per your requirement.

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.