2

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");
Titus
  • 22,031
  • 1
  • 23
  • 33
Walshy
  • 850
  • 2
  • 11
  • 32
  • Take a look at the answer to [this question](http://stackoverflow.com/questions/21294707/htmlunit-ignore-javascript-errors) – Titus Sep 02 '15 at 09:03
  • Real IE8 also gives errors, with `new WebClient(BrowserVersion.CHROME)` you would have another error, which should be fixed in HtmlUnit. – Ahmed Ashour Sep 02 '15 at 10:12

0 Answers0