首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HtmlUnit谷歌登录

HtmlUnit谷歌登录
EN

Stack Overflow用户
提问于 2015-11-01 10:08:11
回答 1查看 760关注 0票数 1

我想自动化google登录并接受oauth以获得身份验证代码。

我通过NullPointerExeption ()得到一个nextButton.click(),找不到"next“按钮。

代码语言:javascript
复制
        WebClient webClient = new WebClient(); //BrowserVersion.FIREFOX_38
        HtmlPage page = webClient.getPage("https://accounts.google.com/o/oauth2/auth?");            

        HtmlTextInput email = (HtmlTextInput)page.getElementById("Email");
        email.setValueAttribute(emailAddress);
        HtmlSubmitInput nextButton = (HtmlSubmitInput)page.getElementById("next");

        HtmlPage newPage = (HtmlPage)nextButton.click();
        webClient.waitForBackgroundJavaScriptStartingBefore(8000);

        HtmlTextInput passwd = (HtmlTextInput)page.getElementById("Passwd");
        passwd.setValueAttribute(password);
        HtmlSubmitInput signIn = (HtmlSubmitInput)page.getElementById("signIn");

        HtmlPage pageSucces = (HtmlPage)signIn.click();
        webClient.waitForBackgroundJavaScriptStartingBefore(8000);

        HtmlSubmitInput submitAccess = (HtmlSubmitInput)page.getElementById("submit_approve_access");
        HtmlPage pageAccess = (HtmlPage)submitAccess.click();
        webClient.waitForBackgroundJavaScriptStartingBefore(8000);

        HtmlTextInput code = (HtmlTextInput)page.getElementById("code");
        System.out.println(code.getText());

我试过这个Can't log in to Google using HtmlUnit - Can't advance to web page for entering password,但没有成功。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-01 15:26:25

问题是网站,html页面不像标准浏览器。登录页面如下所示:https://lh6.ggpht.com/v19i1LtG-IdZKSZ-rhtuflJJmVmZM3gd3uauQQyLFvJxXTxYi4t8ygCQXwutu1nq69mmna8=w351

您还可以查看页面对象,在那里可以看到带有所有可用ID的idMap。

代码语言:javascript
复制
        HtmlTextInput email = (HtmlTextInput)page.getElementById("Email");
        email.setValueAttribute(emailAddress);
        HtmlPasswordInput passwd = (HtmlPasswordInput)page.getElementById("Passwd");
        passwd.setValueAttribute(password);
        HtmlSubmitInput signInButton = (HtmlSubmitInput)page.getElementById("signIn");

        webClient.waitForBackgroundJavaScriptStartingBefore(8000);
        HtmlPage newPage = (HtmlPage)signInButton.click();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33461077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档