LambdaTest Community

Find answers, support, and inspiration from other users

LambdaTest Community

How to capture visible web elements of the list in loop?


I am working on one of the scenario where i have to catch all the elements of the list visible on the page. Then i have to click on next and then again capture visible elements of the list till i get the available date.

Here is my function:

WebDriverWait wait = new WebDriverWait(driver, 1000); while(flag) {

List<WebElement> abc = wait.until(ExpectedConditions .visibilityOfAllElementsLocatedBy(By.xpath("//div//div[@data-tip='No tee-times available']"))); System.out.println(abc.size()); Thread.sleep(1000);

for(WebElement e: abc) { System.out.println(e.getText()+" "); while(e.getText().contains("Tee Times Unavailable")) { try{ WebElement next = driver.findElement(By.xpath("//div[@class='arrow-wrapper next slick-arrow']"));; } catch(StaleElementReferenceException c) { c.printStackTrace(); }

} flag=false;

} }

Can anybody help me with this?

Up Vote Down Vote 1 Votes
Posted 4 months ago
Up Vote Down Vote 0 Votes

  4 months ago Report


Rather then using the gettext Selenium method. you can use the getattribute method which get you the value of the visible element. Here is the sample script to save the page visible element value.

List<WebElement> BrowserList = driver.findElements(By.xpath("//div[@class=\'mCSB_container\']/ul [@class=\'list-unstyled real-browser-test__list-browser text-center\']/li")); 
System.out.println("BrowserList :" + BrowserList.size());              
List<String> BrowserListElements = new ArrayList<>();             
int B;             
for (B = 0; B < BrowserList.size(); B++) 
System.out.println("b" + BrowserListElements);

I hope it'll help.

Up Vote Down Vote 0 Votes
Posted 4 months ago