How to Find more than One Web Elements in the List

0
122

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
  2.  
  3. List elementList = driver.findElements(By.xpath("//myxpath"));
  4.  
  5. // Fetching the size of the list
  6. int listSize = elementList.size();
  7.  
  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 155 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here