Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get dynamically loaded source in selenium

I'm trying to get page content which is dynamically loaded after you get to the end of the page but after use sendKeys(Keys.END) page content seems to be the same.

Any chance to handle it and get new reloaded source? I'm using PhantomJS in Java.

like image 910
falsetto Avatar asked Mar 02 '26 21:03

falsetto


1 Answers

The basic idea is to explicitly wait for a presence or visibility of an element loaded dynamically - then, call the getPageSource() method.

For example, if there is a div with a "additionalContent" class dynamically loaded, here is how you can wait for it to appear:

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.additionalContent")));

// get the page source
System.out.println(driver.getPageSource());
like image 127
alecxe Avatar answered Mar 05 '26 11:03

alecxe