我正在开发一个从网站下载文件的软件。我使用HTMLUnit和HTMLAnchor来调用代码中的click()按钮,但是在我单击该按钮后,这就是我得到的结果。
EcmaError:lineNumber = [10] column = [0] lineSource = [um.or = 0;] name = [TypeError] sourceName = [file:// D:/Office/JS/udm-dom.js] message = [TypeError:无法调用未定义的方法“包含”(file:// D:/Office/JS/udm-dom.js#10)] com.gargoylesoftware.htmlunit.ScriptException:TypeError:无法调用undefined的方法“contains”(file:// D:/Office/JS/udm-dom.js#10)
这是我的代码,
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page1 = webClient.getPage("file:\\" + newrfile);
System.out.println(page1.getUrl());
HtmlForm form = page1.getFormByName("advSearchForm");
HtmlSubmitInput button = form.getInputByName("submit");
HtmlPage page2 = button.click();
System.out.println(page2.asXml());
String page2edit = page2.asXml();
String editjs1 =page2edit.replace("http://www.wipo.int/export/sites/www/shared/scripts/udm4.5/udm-custom.js", "file://D:\\Office\\JS\\udm-custom.js");
String editjs2 =editjs1.replace("http://www.wipo.int/export/sites/www/shared/scripts/udm4.5/udm-control.js", "file://D:\\Office\\JS\\udm-control.js");
String editjs3 =editjs2.replace("http://www.wipo.int/export/sites/www/shared/scripts/udm4.5/menu-wipo.js", "file://D:\\Office\\JS\\menu-wipo.js");
String editjs4 =editjs3.replace("http://www.wipo.int/export/sites/www/shared/scripts/menu/custom-en.js", "file://D:\\Office\\JS\\custom-en.js");
String editjs5 =editjs4.replace("http://www.wipo.int/export/sites/www/shared/scripts/udm4.5/udm-dom.js", "file://D:\\Office\\JS\\udm-dom.js");
String editjs6 =editjs5.replace("http://www.wipo.int/export/sites/www/shared/scripts/udm4.5/udm-mod-keyboard.js", "file://D:\\Office\\JS\\udm-mod-keyboard.js");
String editjs7 =editjs6.replace("www.wipo.int//export/sites/www/shared/scripts/udm4.5/menu-wipo.js", "file://D:\\Office\\JS\\menu-wipo.js");
String editjs8 =editjs7.replace("www.wipo.int/export/sites/www/shared/scripts/menu/custom-en.js", "file://D:\\Office\\JS\\custom-en.js");
String editjs9 = editjs8.replace("<script src=\"/romarin//shared/scripts/animate_fichiers/track.js\" type=\"text/javascript\"></script>"," ");
URL url = new URL("file:\\E://Wipo//2015//17//emptyres//" + rfile.getName());
StringWebResponse response = new StringWebResponse(editjs9, url);
HtmlPage editpage = HTMLParser.parseHtml(response, webClient.getCurrentWindow());
HtmlAnchor htmlAnchor = editpage.getAnchorByText(rfile.getName().replace(".html", ""));
System.out.println(htmlAnchor.click().toString());