Free Source Code and Tutorials

Custom Search

How to find more than one web element in the list?

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:

  1. // Storing the list
  3. List elementList = driver.findElements(By.xpath("//myxpath"));
  5. // Fetching the size of the list
  6. int listSize = elementList.size();
  8. for (int i=0; i<listSize; i++)
  9. {
  10. // Clicking on each service provider link
  11. serviceProviderLinks.get(i).click();
  12. // Navigating back to the previous page that stores link to service providers
  13. driver.navigate().back();
  14. }

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

Facebook Comments
(Visited 7 times, 1 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: