SeleniumHQ / htmlunit-driver

WebDriver compatible driver for HtmlUnit headless browser.
Apache License 2.0
255 stars 86 forks source link

Fetching innerHTML #148

Closed ptriller1und1 closed 4 months ago

ptriller1und1 commented 5 months ago

I am just in the process of upgrading selenium to the newest version and I am trying to switch to htmluit3 in this process but I have not figured out how to get innerHTML with the new version

    HtmlUnitDriver driver  = new HtmlUnitDriver(false);
    driver.get("https://www.google.de");
    System.out.println(driver.findElement(By.tagName("body")).getAttribute("innerHTML"));

This works fine with the old htmlunit driver but returns null in the htmlunit3 verions

When tested it with htmlunit3-driver:4.20.0 it returns null When I tested it with htmlunit-driver:4.13.0 it returns the innerHTML as expected

rbri commented 5 months ago

@ptriller1und1 interesting point - at the moment getting javascript properties (like innerHTML) are not supported if js is disabled.

Technically we only have to disable the support if the javascript engine is disabled (for more about the differences see https://www.htmlunit.org/javascript-howto.html#Enable.2FDisable_JavaScript_support). Will think about that - maybe i have to adjust this...

As a workaround you can do something like

HtmlUnitDriver driver  = new HtmlUnitDriver(true);
driver.getWebClient().getOptions().setThrowExceptionOnScriptError(false);
driver.get("https://www.google.de");
System.out.println(driver.findElement(By.tagName("body")).getAttribute("innerHTML"));
rbri commented 5 months ago

@ptriller1und1 is think you are right in all point here - fixed now.

Will do a release later today.