HtmlUnit Java Button单击警告

时间:2014-05-07 12:33:32

标签: java javascript html warnings htmlunit

我尝试编写一个程序,我可以登录我的mlg帐户。我正在使用HtmlUnit。这是我的代码:

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());

    }
}

我测试了代码并且它运行得很好,但是我得到了这些警告并且它使程序非常慢:

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

我确定该行

page = button.click();

是警告的原因。谁能帮我?我应该使用其他任何东西,然后HtmlUnit?或者有人知道如何压制警告吗?

谢谢:)

1 个答案:

答案 0 :(得分:0)

他们似乎只是JS警告。很可能是因为JS引擎不喜欢代码的某些部分。如果过程正常,请忽略它们。

如果你想关闭它们,我很可能会回答这个问题的答案(你只需要添加2行):Turning HtmlUnit Warnings off