Hi everyone!
I am super excited to see there is something compatible with Selenium that I can use to unit test with. My test works as follows:
In the constructor, I initialize a new WebDriver:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions(BrowserVersion.CHROME);
options.setJavaScriptEnabled(true)
.setCapability(HtmlUnitOption.optThrowExceptionOnScriptError, false);
webDriver = new HtmlUnitDriver(options);
Then later on in a different method call, I instruct it to load a static resource. In this case, it is a rendered HTML file from twitter. I then immediately after instruct it to wait for the JavaScript to finish executing by waiting for the root node to finish rendering.
String currentDirectory = System.getProperty("user.dir");
webDriver.get("file:///" + currentDirectory + "/resources/test/web/twitter_source.html");
WebDriverWait jsWait = new WebDriverWait(webDriver, Duration.ofSeconds(20));
jsWait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id("react-root")));
This all works well.
Then even later in the code, I run a JavaScript file that crawls the DOM and adds style attributes to each node. For example:
When HtmlUnit processes this file, I get the exception or error message in the issue title:
Cannot invoke "org.htmlunit.corejs.javascript.Scriptable.getParentScope()" because "obj" is null
I tried to look up the javadoc for ScriptableObject but I get a 404 and so I cannot debug further. Any indication as to what the issue may be? I don't know what "obj" refers to. This code runs in Java Selenium with a ChromeDriver v127, so the JavaScript script should be fine. This only happens on HtmlUnit.
https://www.htmlunit.org/apidocs/org/htmlunit/corejs.javascript.ScriptableObject.html
Any help is appreciated. Thanks!
Hi everyone!
I am super excited to see there is something compatible with Selenium that I can use to unit test with. My test works as follows:
In the constructor, I initialize a new WebDriver:
Then later on in a different method call, I instruct it to load a static resource. In this case, it is a rendered HTML file from twitter. I then immediately after instruct it to wait for the JavaScript to finish executing by waiting for the root node to finish rendering.
This all works well.
Then even later in the code, I run a JavaScript file that crawls the DOM and adds style attributes to each node. For example:
When HtmlUnit processes this file, I get the exception or error message in the issue title:
I tried to look up the javadoc for ScriptableObject but I get a 404 and so I cannot debug further. Any indication as to what the issue may be? I don't know what "obj" refers to. This code runs in Java Selenium with a ChromeDriver v127, so the JavaScript script should be fine. This only happens on HtmlUnit.
https://www.htmlunit.org/apidocs/org/htmlunit/corejs.javascript.ScriptableObject.html
Any help is appreciated. Thanks!