我正在使用HtmlUnit,而我目前正在尝试登录网站。问题是,当我运行代码时,我收到一个指向我的getPage(...)
行(下面的代码)的巨大错误,它有错误:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError:
Cannot call method "appendChild" of undefined (script in
http://bukkit.org/login from (77, 13) to (85, 14)#84)' I have just
tried to use the code to login. It is just like the example code on
the website.
代码:
try(final WebClient web = new WebClient()) {
final HtmlPage login = web.getPage("http://bukkit.org/login");
final HtmlForm form = (HtmlForm) login.getElementById("pageLogin");
String username;
String password;
print("Please enter your username: ");
username = scanner.nextLine();
print("Please enter your password: ");
password = scanner.nextLine();
final HtmlTextInput name = form.getInputByName("login");
name.setValueAttribute(username);
final HtmlPasswordInput pswd = form.getInputByName("password");
pswd.setValueAttribute(password);
final HtmlSubmitInput button = form.getInputByValue("Log in");
button.click();
}
导致错误的行是
final HtmlPage login = web.getPage("http://bukkit.org/login");