Whenever I try to set HtmlUnit enableJavaScript to true, it returns this error:
org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking getOffsetTop
I set it to true with this:
driver = new HtmlUnitDriver(true);
Before setting enableJavaScript(true), I was receiving an error with this specific line of code:
WebElement checkoutEmail = driver.findElement(By.id("checkout_email"));
javascriptExecutor.executeScript("arguments[0].value='abc@gmail.com';", checkoutEmail);
Previous error message:
java.lang.UnsupportedOperationException: Javascript is not enabled for this HtmlUnitDriver instance
So basically, after setting it to true, I receive another brand new error. Update I fixed this by adding this:
public class CustomHtmlUnitDriver extends HtmlUnitDriver {
@Override
protected WebClient modifyWebClient(WebClient client) {
WebClient modifiedClient = super.modifyWebClient(client);
modifiedClient.getOptions().setThrowExceptionOnScriptError(false);}}
And then I added ((CustomHtmlUnitDriver) driver).setJavascriptEnabled(true);