Wait- Expected conditions not working for auto-suggestion within Yahoo Finance page using Selenium and Java

Below code is not able to identify the list of webelements if they are identified inside a wait condition. I get an exception as timeoutexception and unable to identify the element for the specified xpath.

However if I directly access the elements without wait condition , the values are assigned to the list Variable, why is this so?

WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.get("https://www.finance.yahoo.com");
driver.manage().window().maximize();
driver.findElement(By.xpath("//input[@id='yfin-usr-qry']")).sendKeys("nclh");

WebDriverWait wait = new WebDriverWait(driver,5);
List<WebElement>dd_list= wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//ul[@class='modules_list__1zFHY']/li")));
System.out.println(dd_list.size());

for(WebElement ele : dd_list) {

    if (ele.getText().contains("NCLH.VI")) {
        System.out.println("i got the element");
    }
}


Read more here: https://stackoverflow.com/questions/64898016/wait-expected-conditions-not-working-for-auto-suggestion-within-yahoo-finance-p

Content Attribution

This content was originally published by my3rddimension at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: