0

I have made a post before about this but have gained some more details on how to do it, yet i am still unable to do it properly. This is the main part of code. When i run it i get a whole bunch of warnings related to css in the console. And it wont work. Im trying to get the user's name as i mentioned in the code.If someone could help it would mean a lot to me. The website is my school website: https://lionel2.kgv.edu.hk/login/index.php . I have included the logged on website ( I removed most elements except for my user part ) if that helps. Thanks in advance,

Vijay.

website: https://drive.google.com/a/kgv.hk/file/d/0B-O_Xw0mAw7tajJhVlRxTkFhOE0/view?usp=sharing

   //most of this is from https://gist.github.com/harisupriyanto/6805988

    String loginUrl = "http://lionel2.kgv.edu.hk";
    int loginFormNum = 1;
    String usernameInputName = "nameinput";
    String passwordInputName = "passinput";
    String submitLoginButtonValue = "Sign In";

    // create the HTMLUnit WebClient instance
    WebClient wclient = new WebClient();

    // configure WebClient based on your desired
    wclient.getOptions().setPrintContentOnFailingStatusCode(false);
    wclient.getOptions().setCssEnabled(true);
    wclient.getOptions().setThrowExceptionOnFailingStatusCode(false);
    wclient.getOptions().setThrowExceptionOnScriptError(false);

try {

      final HtmlPage loginPage = (HtmlPage)wclient.getPage(loginUrl);

      final HtmlForm loginForm = loginPage.getForms().get(loginFormNum);

      final HtmlTextInput txtUser = loginForm.getInputByName(usernameInputName);
      txtUser.setValueAttribute(username);
      final HtmlPasswordInput txtpass = loginForm.getInputByName(passwordInputName);
      txtpass.setValueAttribute(password);
      final HtmlSubmitInput submitLogin = loginForm.getInputByValue(submitLoginButtonValue);


      final HtmlPage returnPage = submitLogin.click();  

      final HtmlElement returnBody = returnPage.getBody(); 
      //if (//there is a class called "Login info, then print out the     nodeValue.) {

     // }

    } catch(FailingHttpStatusCodeException e) {
      e.printStackTrace();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
Vijay
  • 1
  • 2

1 Answers1

0

You most likely do not need the CSS so you could disable it.

To improve performance and reduce warnings and errors I disable/limit as much as possible.

    webClient.setJavaScriptTimeout(30 * 1000); // 30s
    webClient.getOptions().setTimeout(300 * 1000); // 300s
    webClient.getOptions().setCssEnabled(false);
    webClient.getOptions().setThrowExceptionOnScriptError(false); // no Exceptions because of javascript
    webClient.getOptions().setPopupBlockerEnabled(true); 
MrSmith42
  • 9,961
  • 6
  • 38
  • 49
  • Thanks for the reply I added those but i get these errors: https://docs.google.com/a/kgv.hk/document/d/1FPdOCfYGzjgidddPUDN3GZtL-TDAn5b_OrQiLIlW8Mo/edit?usp=sharing – Vijay Sep 27 '16 at 14:13
  • if you know how to please message me, i would really really appreciate it. – Vijay Sep 27 '16 at 14:14