ReferenceError: "validate" is not defined. while trying to submit a form with HTMLUnit

ReferenceError: "validate" is not defined. while trying to submit a form with HTMLUnit

我想使用 HTML 单位向 this 网站提交表单,但我收到标题错误。

这是我的代码:

try (final WebClient webClient = new WebClient(BrowserVersion.CHROME, "127.0.0.1", 57703)) {
    //webClient.getOptions().setThrowExceptionOnScriptError(false);
    final HtmlPage page1 = webClient.getPage("http://tagmp3.net/");
    final HtmlDivision div = (HtmlDivision) page1.getElementById("urlForm");
    final DomNodeList<DomElement> forms = page1.getElementsByTagName("form");
    final HtmlForm form = (HtmlForm) forms.get(0);
    final HtmlTextInput textField = form.getInputByName("filepath");
    final HtmlSubmitInput button = form.getInputByName("button");
    textField.setValueAttribute(url);
    final HtmlPage page2 = button.click();
    System.out.println(page2.getBaseURL());
}

这是我得到的错误:

EcmaError: lineNumber=[4] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[http://code.jquery.com/jquery-3.1.1.min.js] message=[TypeError: Cannot set property "innerHTML" of undefined to "<form></form><form></form>" (http://code.jquery.com/jquery-3.1.1.min.js#4)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property "innerHTML" of undefined to "<form></form><form></form>" (http://code.jquery.com/jquery-3.1.1.min.js#4)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:894)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:637)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:518)      
    blah blah blah....

我试图关闭脚本错误,但没有成功。

顺便说一句,我在网站的 HTML 中找到了这个:

<form onsubmit="return validate(this)" method="post" action="index.php">

我怎样才能解决这个问题?

Edge 支持还不完善,请用 Firefox 52 或 Chrome 模拟试试。另外请使用最新的快照版本。

在顶部添加这一行:

webClient.getOptions().setJavaScriptEnabled(false);