- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试自动登录 Gmail,但它不起作用。我使用 HtmlUnit 进行表单、文本框和提交按钮访问。在传递正确的用户名和密码后,它会显示所有服务,但最终当我打开 gmail 时,它会显示登录页面。
这是我的代码
final WebClient webClient = new WebClient(BrowserVersion.CHROME);
// Get the first page
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
try {
final HtmlPage page1 = webClient.getPage("http://www.gmail.com/");
final HtmlForm form = page1.getForms().get(0);
final HtmlSubmitInput button = form.getInputByName("signIn");
final HtmlTextInput textField = form.getInputByName("Email");
final HtmlPasswordInput pwd = form.getInputByName("Passwd");
textField.setValueAttribute("username");
pwd.setValueAttribute("password");
System.out.println(page1.asText());
final HtmlPage page2 = (HtmlPage) button.click();
String htmlBody = page2.getWebResponse().getContentAsString();
System.out.println(page2.asText());
System.out.println("Base Uri 1 : " + page1);
System.out.println("Base Uri 2 : " + page2);
webClient.closeAllWindows();
} catch (Exception e) {
// TODO: handle exception
}
这是我收到的错误日志
Oct 17, 2014 8:51:09 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "email", creating a text input
Gmail
One account. All of Google.
Sign in to continue to Gmail
Email username Password password Sign in checked Stay signed in
For your convenience, keep this checked. On shared devices, additional precautions are recommended. Learn more
Need help?
Create an account
One Google Account for everything Google
About Google
Privacy & Terms
Help
?English (United States)?
Oct 17, 2014 8:51:20 PM com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl runSingleJob
SEVERE: Job run failed with unexpected RuntimeException: CustomError: Error in protected function: Cannot call method "Xi" of null (script in https://mail.google.com/_/scs/mail-static/_/js/k=gmail.main.en.abFelT_TrjE.O/m=m_i,t,it/am=HCOG-3_3B5Ez3KUPqv3733OfFD97D_7vTQAk7ASA_83-H0Dvgf1Qfmg/rt=h/d=1/t=zcms/rs=AItRSTMh1uD80u0Q-oPCPkAWIHZAIOe3nQ from (57, 18) to (114, 10)#67)
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException]
com.gargoylesoftware.htmlunit.ScriptException: CustomError: Error in protected function: Cannot call method "Xi" of null (script in https://mail.google.com/_/scs/mail-static/_/js/k=gmail.main.en.abFelT_TrjE.O/m=m_i,t,it/am=HCOG-3_3B5Ez3KUPqv3733OfFD97D_7vTQAk7ASA_83-H0Dvgf1Qfmg/rt=h/d=1/t=zcms/rs=AItRSTMh1uD80u0Q-oPCPkAWIHZAIOe3nQ from (57, 18) to (114, 10)#67)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:705)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:620)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:513)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:637)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:612)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1001)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:53)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:328)
at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:162)
at java.lang.Thread.run(Unknown Source)
Caused by: net.sourceforge.htmlunit.corejs.javascript.JavaScriptException: [object Object] (script in https://mail.google.com/_/scs/mail-static/_/js/k=gmail.main.en.abFelT_TrjE.O/m=m_i,t,it/am=HCOG-3_3B5Ez3KUPqv3733OfFD97D_7vTQAk7ASA_83-H0Dvgf1Qfmg/rt=h/d=1/t=zcms/rs=AItRSTMh1uD80u0Q-oPCPkAWIHZAIOe3nQ from (57, 18) to (114, 10)#67)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1006)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:411)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:309)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3057)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:103)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:630)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:690)
... 10 more
JavaScriptException value = [object Object]
== CALLING JAVASCRIPT ==
function () {
if (b.isDisposed()) {
return a.apply(this, arguments);
}
try {
return a.apply(this, arguments);
}
catch (c) {
b.xa(c);
if (!b.Ba) {
throw b.Aa && ("object" === typeof c ? c.message = "Error in protected function: " + c.message : c = "Error in protected function: " + c), c;
}
throw new Yba(c);
}
finally {
}
}
======= EXCEPTION END ========
Oct 17, 2014 8:51:21 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:21 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:22 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:22 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:22 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:22 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 17, 2014 8:51:22 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Gmail
Basic HTML view
<style> #loading {display:none} </style><form action="?ui=html&zy=c" method="post"><input type="hidden" name="at" value="AF6bupN_lVxTXggheNEbct_StIuAzk-YxQ"><font face=arial>JavaScript must be enabled in order for you to use Gmail in standard view. However, it seems JavaScript is either disabled or not supported by your browser. To use standard view, enable JavaScript by changing your browser options, then <a href="">try again</a>.<p>To use Gmail's basic HTML view, which does not require JavaScript, <input type="submit" value="click here" class="submit_as_link">.</p></font></form><form action="?ui=mobile&zyp=c" method="post"><input type="hidden" name="at" value="AF6bupN_lVxTXggheNEbct_StIuAzk-YxQ"><p><font face=arial>If you want to view Gmail on a mobile phone or similar device <input type="submit" value="click here" class="submit_as_link">.</font></p></form>
Loading harishmohanani28@gmail.com…
Loading standard view | Load basic HTML (for slow connections)
This is taking longer than usual. Try reloading the page.
If that doesn't work, you can:
1. Disable Labs and try again.
2. If you're on a slow connection, try basic HTML view.
3. For more troubleshooting tips, visit the help center.
Skip to content
Using Gmail with screen readers
Keyboard shortcuts
Gmail (standard view) guide
This version of Chrome is no longer supported. Please upgrade to asupported browser. Dismiss
+Harish
+Harish
Search
YouTube
Maps
Play
News
Gmail
Drive
Calendar
Gmail
Add a shortcut
More
Translate
Books
Blogger
Photos
My Business
Even more from Google
Share
Change photo
Harish Mohanani
harishmohanani28@gmail.com
Account–Privacy
View profile
Harish Mohanani
harishmohanani28@gmail.com (default)
All your Google+ pages ›
Add account
Sign out
Search
Hidden fields
Gmail Logo
>
<
Conversations
Primary
Social
Promotions
>
<
English
English Dvorak
??????
???????? (???????)
?????? (INSCRIPT)
Enable personal dictionary
Hide Keyboard
Input Tools Settings
Base Uri 1 : HtmlPage(https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1)@26946257
Base Uri 2 : HtmlPage(https://mail.google.com/mail/u/0/)@16175221
最佳答案
内置浏览器可能无法正确解析Javascript。
尝试模拟不同的浏览器。来自 the docs :
Often you will want to simulate a specific browser. This is done by passing a com.gargoylesoftware.htmlunit.BrowserVersion into the WebClient constructor. Constants have been provided for some common browsers but you can create your own specific version by instantiating a BrowserVersion.
@Test
public void homePage_Firefox() throws Exception {
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17);
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());
webClient.closeAllWindows();
}
此代码段模拟 Firefox v17。您可以查看受支持的可模拟浏览器的完整列表 in these javadocs 。今天,这些是:
static BrowserVersion CHROME
static BrowserVersion FIREFOX_17
static BrowserVersion FIREFOX_24
static BrowserVersion INTERNET_EXPLORER_11
static BrowserVersion INTERNET_EXPLORER_8
static BrowserVersion INTERNET_EXPLORER_9
关于java - 使用 HtmlUnit 登录 Gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26428699/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!