HtmlUnit Java 按钮点击警告

3

我尝试编写一个程序,可以登录到我的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

I'm sure that the line

page = button.click();

是警告的原因。有人能帮我吗?我应该使用除了HtmlUnit之外的别的东西吗?或者有人知道如何去除这个警告吗?

谢谢 :)


你是否找到了关闭Rhino警告的解决方案? - Arya
那其实是相当久以前的事了,但我记得我没有找到解决方法。 - Baeumla
1个回答

0

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

如果你想关闭它们,它们很可能会随着我的回答消失(你只需要添加两行):关闭HtmlUnit警告


谢谢你的回答。 我添加了这些行,但是没有改变任何东西。我收到与之前相同的警告 :/ 我还意识到按钮点击不像我想象的那样起作用。 - Baeumla
因为错误在JS代码中,而且你不能触及服务器的代码,所以很少或几乎没有关于如何修复它的信息。另外,Rhino可能存在漏洞或缺乏对JS正在执行的操作的支持。无论如何,我在这个答案中给出了一些指针,可以帮助解决问题。 - Mosty Mostacho
@MostyMostacho,你有没有找到关闭rhino警告的解决方案? - Arya

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接