admin管理员组文章数量:1022504
I’m submitting a form using java HtmlUnit package. I am able to get pages and submit forms but on one page I’m getting a ScriptException error. The message is “Cannot set property "disabled" of undefined to "0"”
I think it might be caused by a javascript method that tries to set a variable that has not been declared in the form but I’m not sure.
tempForm = MyPage.getFormByName("menu_form");
tempForm.getInputByName("userId").setValueAttribute("myusername");
HtmlPage editSubscriberPage = (HtmlPage)
tempForm.getInputByName("submit_button").click();
EcmaError: lineNumber=[824] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=2322020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)] message=[TypeError: Cannot set property "disabled" of undefined to "0" (script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)]
.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "disabled" of undefined to "0" (script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
at .gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:584)
at .gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1237)
at .gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:183)
at .gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:449)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)
at .gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:179)
at .gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:82)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
at TestOne.run(TestOne.java:77)
at TestOne.main(TestOne.java:215)
I’m submitting a form using java HtmlUnit package. I am able to get pages and submit forms but on one page I’m getting a ScriptException error. The message is “Cannot set property "disabled" of undefined to "0"”
I think it might be caused by a javascript method that tries to set a variable that has not been declared in the form but I’m not sure.
tempForm = MyPage.getFormByName("menu_form");
tempForm.getInputByName("userId").setValueAttribute("myusername");
HtmlPage editSubscriberPage = (HtmlPage)
tempForm.getInputByName("submit_button").click();
EcmaError: lineNumber=[824] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in https://labserver.p./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=2322020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)] message=[TypeError: Cannot set property "disabled" of undefined to "0" (script in https://myserver.pany./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)]
.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "disabled" of undefined to "0" (script in https://labserver.p./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
at .gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:584)
at .gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1237)
at .gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:183)
at .gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:449)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)
at .gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:179)
at .gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:82)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
at TestOne.run(TestOne.java:77)
at TestOne.main(TestOne.java:215)
Share
Improve this question
edited Jul 23, 2009 at 19:45
Ben
asked Jul 22, 2009 at 21:08
BenBen
2,8116 gold badges34 silver badges45 bronze badges
2
- Does viewing the same page in a browser produce a JS error? – seth Commented Jul 23, 2009 at 3:45
- I just tested it again and just noticed the page that loads does have a JS error. Is there a way I can tell HtmlUnit to keep processing like ie does? – Ben Commented Jul 23, 2009 at 18:33
2 Answers
Reset to default 3This was caused my a javascript error on the page that was being loaded. I set the
webClient.getOptions().setThrowExceptionOnScriptError(false);
but it still threw the exception.
SOLUTION: If you catch the ScriptException the page is STILL fully loaded and you can just continue processing and ignoring the exception.
Example of HTML that fails:
<html>
<Head><title>JS Test</title>
<script type="text/javascript">
function run_js()
{
form.myinput.value = "from on body";
// document.myform.myinput.value = "from body";
}
</script>
</head>
<body onload="run_js()">
The Body.
<form name="myform">
<input name="myinput" type="text"/>
</form>
</body>
</html>
Can you provide a public website to test against? As I am not able to load the JS in https://mmlab1msslnx.fmr./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d
Also, please use latest HtmlUnit 2.5 version.
I’m submitting a form using java HtmlUnit package. I am able to get pages and submit forms but on one page I’m getting a ScriptException error. The message is “Cannot set property "disabled" of undefined to "0"”
I think it might be caused by a javascript method that tries to set a variable that has not been declared in the form but I’m not sure.
tempForm = MyPage.getFormByName("menu_form");
tempForm.getInputByName("userId").setValueAttribute("myusername");
HtmlPage editSubscriberPage = (HtmlPage)
tempForm.getInputByName("submit_button").click();
EcmaError: lineNumber=[824] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=2322020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)] message=[TypeError: Cannot set property "disabled" of undefined to "0" (script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)]
.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "disabled" of undefined to "0" (script in .pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
at .gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:584)
at .gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1237)
at .gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:183)
at .gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:449)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)
at .gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:179)
at .gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:82)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
at TestOne.run(TestOne.java:77)
at TestOne.main(TestOne.java:215)
I’m submitting a form using java HtmlUnit package. I am able to get pages and submit forms but on one page I’m getting a ScriptException error. The message is “Cannot set property "disabled" of undefined to "0"”
I think it might be caused by a javascript method that tries to set a variable that has not been declared in the form but I’m not sure.
tempForm = MyPage.getFormByName("menu_form");
tempForm.getInputByName("userId").setValueAttribute("myusername");
HtmlPage editSubscriberPage = (HtmlPage)
tempForm.getInputByName("submit_button").click();
EcmaError: lineNumber=[824] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in https://labserver.p./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=2322020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)] message=[TypeError: Cannot set property "disabled" of undefined to "0" (script in https://myserver.pany./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)]
.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "disabled" of undefined to "0" (script in https://labserver.p./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
at .gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:584)
at .gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at .gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1237)
at .gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:183)
at .gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:449)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:329)
at .gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)
at .gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:179)
at .gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:82)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
at .gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
at TestOne.run(TestOne.java:77)
at TestOne.main(TestOne.java:215)
Share
Improve this question
edited Jul 23, 2009 at 19:45
Ben
asked Jul 22, 2009 at 21:08
BenBen
2,8116 gold badges34 silver badges45 bronze badges
2
- Does viewing the same page in a browser produce a JS error? – seth Commented Jul 23, 2009 at 3:45
- I just tested it again and just noticed the page that loads does have a JS error. Is there a way I can tell HtmlUnit to keep processing like ie does? – Ben Commented Jul 23, 2009 at 18:33
2 Answers
Reset to default 3This was caused my a javascript error on the page that was being loaded. I set the
webClient.getOptions().setThrowExceptionOnScriptError(false);
but it still threw the exception.
SOLUTION: If you catch the ScriptException the page is STILL fully loaded and you can just continue processing and ignoring the exception.
Example of HTML that fails:
<html>
<Head><title>JS Test</title>
<script type="text/javascript">
function run_js()
{
form.myinput.value = "from on body";
// document.myform.myinput.value = "from body";
}
</script>
</head>
<body onload="run_js()">
The Body.
<form name="myform">
<input name="myinput" type="text"/>
</form>
</body>
</html>
Can you provide a public website to test against? As I am not able to load the JS in https://mmlab1msslnx.fmr./mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d
Also, please use latest HtmlUnit 2.5 version.
本文标签: javaHtmlUnit property undefined script errorStack Overflow
版权声明:本文标题:java - HtmlUnit property undefined script error - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745574324a2156925.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论