3

I try to write a program where i can login to my mlg account. I'm using HtmlUnit. Here is my code:

import java.net.*;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.*;
import java.io.IOException;
import org.apache.commons.logging.LogFactory;


public class test {


        public static void main(String... args) throws FailingHttpStatusCodeException, MalformedURLException, IOException{

            //supress first warnings
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
            LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

            WebClient webClient = new WebClient(BrowserVersion.CHROME);
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setThrowExceptionOnScriptError(false);

            HtmlPage page = webClient.getPage("https://accounts.majorleaguegaming.com/");

            HtmlForm form = page.getForms().get(0);

            System.out.println(page.getTitleText());
            //Edited my username & Password
            form.getInputByName("login").setValueAttribute("MYUSERNAME");
            form.getInputByName("password").setValueAttribute("MYPASSWORD");

            HtmlElement button = form.getInputByName("commit");

            page = button.click();

            System.out.println("AFTER CLICK");
            System.out.println(page.getTitleText());
            System.out.println(page.asText());

    }
}

I tested the code and it works very well, but i get these warnings and it makes the program very slow:

RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getTabIndex() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getTabIndex() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setTabIndex(int) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getTabIndex() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setTabIndex(int) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getOuterHTML() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getOuterHTML() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setOuterHTML(java.lang.String) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getOuterHTML() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setOuterHTML(java.lang.String) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getChildren() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getChildren() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getChildren() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getLang() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getLang() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setLang(java.lang.String) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getLang() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public void com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setLang(java.lang.String) of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getScrollWidth() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getScrollWidth() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public int com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getScrollWidth() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getId() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object public java.lang.String com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getId() of class net.sourceforge.htmlunit.corejs.javascript.MemberBox where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
...i deleted the rest

I'm sure that the line

page = button.click();

is the reason for the warning. Can anyone help me? Should i use anything else then HtmlUnit? Or does anyone know how to supress the warning?

Thanks :)

Baeumla
  • 443
  • 3
  • 6
  • 18

1 Answers1

0

They just seem to be JS warnings. Most likely because the JS engine doesn't like some parts of the code. Disregard them if the process work properly.

If you want to turn them off they would most likely go away with my answer to this question (you just have to add 2 lines): Turning HtmlUnit Warnings off

Community
  • 1
  • 1
Mosty Mostacho
  • 42,742
  • 16
  • 96
  • 123
  • Thank you for your answer. I added those lines but it didn't change anything. I get the same warnings as before :/ I also recognized that the button-click wouldn't work like i thought it would. – Baeumla May 07 '14 at 14:33
  • So there is little no none about how to fix it because the error is in the JS code and you can't touch the server's code. Alternatively, Rhino could have a bug or lack support to whatever the JS is doing. In any case, I've given some pointers on this other [answer](http://stackoverflow.com/questions/20315330) that could help – Mosty Mostacho May 07 '14 at 19:30
  • @MostyMostacho Did you ever find a solution to turning off rhino warnings? – Arya Jun 12 '17 at 02:19