Nidje Nidje - 3 years ago 469
HTML Question

Java Selenium, storing updated page source after javascript activation

I have managed to open a browser with my link and activate the javascript, which allows the page to display more results. Once this is done I am trying to print the new updated page source in the console but all it shows is the original source prior to the javascript activation. My code so far is shown below.

WebDriver driver = new FirefoxDriver();


if (driver instanceof JavascriptExecutor)
throw new IllegalStateException("No support for JavaScript!");

Answer Source

You have to get attribute "innerHTML" of body instead of pageSource:

String bodyHtml = driver.findElement(By.tagName("body")).getAttribute("innerHTML");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download