java - HtmlUnit property undefined script error -
I am submitting a form using the Java HtmlUnit package. I'm able to get pages and submit forms, but on one page I'm getting a ScriptException error message is "Can not set property" disabled "insufficient" "0" "
I think It is possible that this may be due to a JavaScript method that attempts to set a variable which has not been declared in the form but I am not sure.
tempForm = MyPage .getFormByName ("menu_form"); tempForm.getInputByName ("user Ta id ") setValueAttribute (" myusername ") .; Actimelpij edit Krensbsilibrafej = (Acaelpiaf) Temppformkgetinputbi-name (" Sbmit_btn "). Click (); EcmaError: Lainnanbr = [824] columns = [0] line source = [Empty] name = [type error] source name = [https://labserver.comp.com/mcwebadm/cgi-bin/edit_local.pl?operation=edit& script; return_address =% 2Fmcwebadm% 2Fcgi-bin% 2Fmenu .pl & amp; selected = (9, 32) to (840, 15)] message = [Writing error 2322020c341b11de96c3000423d43f1d: to "0" (in the script undefined) Trust can not find "disabled" https://myserver.company.com/mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d (9 , 32) to (840 to 15, # 824)] com.gargoylesoftware.htmlinit.ScriptException: TypeError: Undefined property can not set "disabled" for "0" (https://labserver.comp.com Script in /mcwebadm/cgi-bin/edit_local.pl)? Operation = Edit and Ritrn_ address from =% 2Fmcwebadm% 2Fcgi-bin% 2Fmenu.pl selected = 22020c341b11de96c3000423d43f1d (9, 32) to (840, 15) # 824) com.gargoylesoftware.htmlinit.javascript.JavaScriptEngine at $ HtmlUnitContextAction.run (JavaScriptEng In.java.t34) at net.sourceforge.htmlunit.corejs.javascript.Context.call (Java / 15) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call (ContextFactory.java:507) Com on com.gargoylesoftware.htmlinit.javascript.host.EventListenersContainer.executeEventHandler at com.gargoylesoftware.htmlinit.html.htmlPage.executeJavaScriptFunctionIfPossible (HtmlPage.java:992) .gargoylesoftware.htmlInte.javascript.javascriptInGreenConfold (JavaScriptEngine.javaache64 ) Com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent (No de.java:584) on Net.sourceforge.htmlunit.corejs.javascript.Context.call on com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners (EventListenersContainer.java:177) to (EventListenersContainer.java:164) Com.sworldsoft.html.html at net.sourceforge.htmlunit.corejs.javascript.html.htmlelement $ 2.run (HtmlElement.java:936) .ContextFactory.call (ContextFactory.j AVA: 507) com.gargoylesoftware.htmlunit.html. .HtmlPage.initialize on HtmlElement.fireEvent (HtmlElement.java:941) com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded (HtmlPage.java:1237) on com.gargoylesoftware.htmlunit.html on (HtmlPage.java:183) com .gargoylesoftware.htmlunit.WebClient.loadWebResponseInto (WebClient.java:449) at com.gargoylesoftware.htmlunit.WebClient.getPage (WebClient.java:329) at com.gargoylesoftware htmlunit.WebClient.getPage (WebClient.java:354) on com.gargoylesoftware.htmlunit.html.HtmlForm.submit on com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction (HtmlForm.java:179) (HtmlSubmitInput.java:82) Com.gargoylesoftware.htmlunit.html.htmlElement.click at (com.argagles.html.html.html at HtmlElement.java:1329) com com.argarges.html.html html com / html.html.html (HTML.Element.java: 1288) Click on html.Element.click TestOne.run (HtmlElement.java:12257) at TestOne.main (TestOne.java:77) (TestOne Java: 215)
This was the reason for a javascript error on my page. I set
webClient.getOptions (). SetThrowExceptionOnScriptError (wrong);
But it still threw an exception
Solution: If you capture ScriptException, the page is still full and you only process the exception and ignore can do.
Example of HTML that fails:
& lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; JS Test & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function run_js () {form.myinput.value = "From the body"; // document.myform.myinput.value = "body"; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "run_js ()" & gt; the body. & Lt; Name of the form = "MyForm" & gt; & Lt; Input name = "myinput" type = "text" / & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment