0

I know when we use HTMLUnit, they want exactly perfect javascript running on its Web client. But how do we handle when javascript code like

document.createNodeIterator(root,NodeFilter.SHOW_ALL,null,false);

It complains "Cannot find function createNodeIterator in object" which on document.createNodeIterator works fine on browser.

Here is stack trace:

com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function createNodeIterator in object [object HTMLDocument]. (https://cdn01.icims.com/platform_14.2.150421.78248/erac.icims.com/icims2/servlet/icims2?module=AppInert&action=bundleJavascript&scripts=%2Fportal%2Fjquery-1.8.0.js%2C%2Flib%2Fdomreplacement%2FdomReplacement.js%2C%2Fcommon%2Ficims.js%2C%2Fportal%2Futils.js%2C%2Fportal%2FshowMoreTextAbstract.js%2C%2Fportal%2Ffield.js%2C%2Fportal%2Flogin.js%2C%2Ffield%2Fvalidate.js%2C%2Fcommon%2FicimsTrickle.js%2C%2Fcommon%2FicimsDropdown.js%2C&a=1429647520000#21)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705) [htmlunit-2.15.jar:2.15]
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620) [htmlunit-core-js-2.15.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513) [htmlunit-core-js-2.15.jar:na]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventListeners(EventListenersContainer.java:179) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:239) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:824) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:748) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.HtmlElement$1.run(HtmlElement.java:920) [htmlunit-2.15.jar:2.15]
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620) [htmlunit-core-js-2.15.jar:na]
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513) [htmlunit-core-js-2.15.jar:na]
    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:925) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1298) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:290) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:475) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPageIfPossible(BaseFrameElement.java:184) [htmlunit-2.15.jar:2.15]
    at com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPage(BaseFrameElement.java:122) [htmlunit-2.15.jar:2.15]
OhBeWise
  • 5,350
  • 3
  • 32
  • 60
Jin Lin
  • 293
  • 1
  • 6
  • 16
  • There's nothing wrong with that script - createNodeIterator is just a newer JS function. My guess is that htmlunit's javascript engine doesn't support it (or maybe this is an old version) – Katana314 Apr 23 '15 at 21:48
  • @katana314 I am using htmlunit 2.15 which is the second newest version. do you think I should update it to 2.16? – Jin Lin Apr 24 '15 at 14:41

1 Answers1

1

NodeIterator was just implemented, please give the latest snapshot a try.

Test cases can be found here

Latest snapshot can be found in maven or build server (login as guest)

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
  • @ashour I didn't see the createNodeIterator method under NoteIterator class. Will this method handle javascript "document.createNodeIterator(root,NodeFilter.SHOW_ALL,null,false);" ? – Jin Lin Apr 27 '15 at 05:10
  • @ashour btw, thanks for letting me this. Just wondering if this version will handle createNodeIterator in some way. – Jin Lin Apr 27 '15 at 05:18
  • Yes, it is implemented in 2.17-SNAPSHOT, which will be released in around 3 months. (2.16 was recently released). – Ahmed Ashour Apr 27 '15 at 06:41