I am using HtmlUnit and I'm currently trying to login to a website. The issue is that when I run the code I get a huge error pointing to my getPage(...)
line (Code below) and it has the error:
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.
Code:
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();
}
The line causing the error is
final HtmlPage login = web.getPage("http://bukkit.org/login");