SeleniumHQ / SeleniumHQ/htmlunit-driver
Cannot invoke "org.htmlunit.corejs.javascript.Scriptable.getParentScope()" because "obj" is null
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 266
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
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:
style-boundingx
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!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with the HtmlUnitDriverOptions setup and resources/test/web/twitter_source.html, then inspect the later JavaScript file that crawls the DOM and adds style attributes. Compare the behavior with ChromeDriver and trace the null Scriptable involved; done means the same DOM-processing script runs without the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- testing-qa, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100