I am trying to get started with using Webdriver and headless browsers and am running into some difficulties. I unfortunately cannot share all of my code but I can show how I am setting it up. So let me precede this by saying that the basic use case I tried implementing I did so with the chrome driver to make sure It was not something more mundane like a bad xpath, and the script worked perfectly. Below is how I am initializing htmlunit and beneath that are some of the many errors that arise
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME)
driver.setJavascriptEnabled(true)
on my login page using htmlunit driver works like a champ, once I get to the main page of the app however things fall apart.
SEVERE: Job run failed with unexpected RuntimeException: TypeError: Cannot call method "add" of undefined (http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js#12)
======= EXCEPTION START ========
EcmaError: lineNumber=[12] column=[0] lineSource=[null] name=[TypeError] sourceName= [http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js] message=[TypeError: Cannot call method "add" of undefined (http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js#12)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "add" of undefined (http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js#12)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:684)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:53)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:328)
at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)
at java.lang.Thread.run(Unknown Source)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot call method "add" of undefined (http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js#12)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3638)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2195)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2189)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
... 10 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot call method "add" of undefined (http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js#12)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3624)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3638)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2195)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2189)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1333)
at script(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:12)
at script.Og(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:105)
at script.Pg(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:105)
at script(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:115)
at script(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:108)
at script.Tg(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:105)
at script(http://s.ytimg.com/yts/jsbin/www-embed-player-vfl2yUXMY.js:117)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:609)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:602)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:616)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:591)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:985)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:53)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:328)
at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)
at java.lang.Thread.run(Unknown Source)
== CALLING JAVASCRIPT ==
function () {
Tg(d, b);
}
In addition to this I get a substantial number of warnings like this:
Nov 19, 2013 1:51:42 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
I suspect due to all of these errors my javascript was not actually loading. To verify this I took the page source on my main page when I run the test with Chrome and then did the same thing with HtmlUnit, and that confirmed my suspicions. None of the html that the javascipts generate were present. Our site uses JQuery, Knockout and a couple of other plugins, all libraries that are rather common place, none of which are a issue with chrome driver or raise any kind of error in dev tools console when I run the app. Any help would be greatly appreciated.