Selenium – For loop to navigate to the web element list and verify list item.

Step 1: Store item of the list in a List using findElements

List<WebElement> searchResultlist = Driver.driver.findElements(By.xpath("//span[@class='document-name']"));

Step 2: Use for loop to traverse in the list and verify the text using IF condition.
To make sure input by the user and text from the application are in same case, convert both the strings in UPPER case and match.

for (WebElement resultList : searchResultlist){
     if (resultList.getText().toUpperCase().contains(DocumentNumber.toUpperCase())){;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s