code: public static HtmlPage toHtmlPage(WebDriver webDriver) {
          try {
              return HTMLParser.parseHtml(
                      new StringWebResponse(webDriver.getPageSource(), new URL(webDriver.getCurrentUrl())),
                      new WebClient().getCurrentWindow()
              );
          } catch (IOException e) {
              throw new RuntimeException("Error creating HtmlPage from WebDriver.", e);
          }
      }
docs: Create a {@link HtmlPage} from a given {@link WebDriver} that has been navigated to a HTML page.
  
  @param webDriver {@link WebDriver} that has been navigated to a HTML page
  @return {@link HtmlPage} for the {@link WebDriver}