gpt4 book ai didi

java - HtmlUnit Java 按钮点击警告

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:34 25 4
gpt4 key购买 nike

我尝试编写一个可以登录到我的 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 吗?或者有谁知道如何抑制警告?

谢谢:)

最佳答案

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

如果您想关闭它们,它们很可能会随着我对这个问题的回答而消失(您只需添加 2 行):Turning HtmlUnit Warnings off

关于java - HtmlUnit Java 按钮点击警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23517975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com