Skip to content Skip to sidebar Skip to footer

How To Extract Html Through Javascript Executor?

import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public class oo { public static void

Solution 1:

To extract and print the Page Source through JavascriptExecutor you can use the following (Java based) solution:

  • Syntax:

    String page_source = ((JavascriptExecutor)driver).executeScript("return document.documentElement.innerHTML;").toString();
    System.out.println(page_source);
    

Note: You need to induce a waiter for the page to load completely before extracting the Page Source.

Post a Comment for "How To Extract Html Through Javascript Executor?"