Test dynamically loaded content with Selenium Web Driver Test dynamically loaded content with Selenium Web Driver selenium selenium

Test dynamically loaded content with Selenium Web Driver


I would recommend using WebDriverWait with ExpectedConditons.

//scroll down with Javascript firstWebDriverWait wait = new WebDriverWait(driver, 30);WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("selector")));//interact with your elementelement.click()

Take a look at the guidance provided by Selenium Official page:http://seleniumhq.org/docs/04_webdriver_advanced.html


try using fluent wait in particular. The main feature is:

An implementation of the Wait interface that may have its timeout and polling interval configured on the fly.Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.

public WebElement fluentWait(final By locator){        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)                .withTimeout(30, TimeUnit.SECONDS)                .pollingEvery(5, TimeUnit.SECONDS)                .ignoring(NoSuchElementException.class);        WebElement foo = wait.until(new Function<WebDriver, WebElement>() {            public WebElement apply(WebDriver driver) {                        return driver.findElement(locator);                }                });                           return  foo;              }     ;

The method described returns you web element you can operate with.So the approach be the following:1) you need to find the selectors of elements you expect to be rendered after scrollinge.g.

String cssSelector = "blablabla"

2) scroll down with js3)

WebElement neededElement  = fluentWait(cssSelector);neededElement.click();//neededElement.getText().trim();

you can get more info about fluent wait here


I think the problem is waiting for the dynamic content to finish loading. Try to wait 3 seconds just before findElementsBy? In C# the code would be Thread.Sleep(3000);