我正在尝试登录我的大学网站,但遇到了 html 单元的问题。
我的代码:
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
webClient.setJavaScriptEnabled(false);
webClient.setThrowExceptionOnScriptError(false);
HtmlPage currentPage = webClient.getPage("http://www.oid.hacettepe.edu.tr/cgi-bin/menuindex.cgi");
HtmlForm form = currentPage.getForms().get(0); // forms correct
System.out.println(form.asXml());
HtmlTextInput name = form.getInputByName("login");
HtmlPasswordInput pass = form.getInputByName("passwd");
name.setValueAttribute("*****");
pass.setValueAttribute("*****");
HtmlSubmitInput button = form.getInputByName("SubmitName");
HtmlPage page2 = button.click();
System.out.println(page2.asText());
结果 :
Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[name] attributeValue=[login]
at com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName(HtmlForm.java:460)
at hacettepe.Hacettepe.main(Hacettepe.java:34)
Java Result: 1
你能解释一下我对这个问题的想法有什么问题吗?非常感谢。