Java HtmlUnit属性未定义脚本错误
我正在使用java HtmlUnit包提交表单。我能够获取页面并提交表单,但在一个页面上,我遇到了ScriptException错误。消息为“无法将未定义的属性“已禁用”设置为“0” 我认为这可能是由于javascript方法试图设置一个未在表单中声明的变量造成的,但我不确定Java HtmlUnit属性未定义脚本错误,java,javascript,html,Java,Javascript,Html,我正在使用java HtmlUnit包提交表单。我能够获取页面并提交表单,但在一个页面上,我遇到了ScriptException错误。消息为“无法将未定义的属性“已禁用”设置为“0” 我认为这可能是由于javascript方法试图设置一个未在表单中声明的变量造成的,但我不确定 tempForm = MyPage.getFormByName("menu_form"); tempForm.getInputByName("userId").setValueAttribute("myusername")
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.comp.com/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.company.com/mcwebadm/cgi-bin/edit_local.pl?operation=edit&return_address=%2Fmcwebadm%2Fcgi-bin%2Fmenu.pl&selected=22020c341b11de96c3000423d43f1d from (9, 32) to (840, 15)#824)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "disabled" of undefined to "0" (script in https://labserver.comp.com/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 com.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 com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:584)
at com.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 com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1237)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:183)
at 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)
at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:179)
at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:82)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
at TestOne.run(TestOne.java:77)
at TestOne.main(TestOne.java:215)
你能提供一个公共网站进行测试吗?因为我无法加载JS
另外,请使用最新的HtmlUnit 2.5版本。这是由于加载页面上的javascript错误造成的。 我设定了 webClient.getOptions().SetThroweExceptionOnScriptError(false) 但它仍然抛出了例外 解决方案:如果捕获到ScriptException,则页面仍处于完全加载状态,您可以继续处理并忽略异常 失败的HTML示例:
<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>
JS测试
函数run_js()
{
form.myinput.value=“从正文开始”;
//document.myform.myinput.value=“来自正文”;
}
身体。
在浏览器中查看同一页面是否会产生JS错误?我刚刚再次测试了它,并注意到加载的页面确实存在JS错误。有没有办法让HtmlUnit像ie一样继续处理?我无法提供公共测试用例。我正在努力创造一个。我已经检查过了,我正在使用2.5版。我希望有人见过类似的东西。