HtmlUnit - 2021 年登录谷歌账户

时间:2021-01-29 13:41:15

标签: java htmlunit

我正在尝试使用 HtmlUnit 登录 google。然而,我似乎做错了什么,因为我坚持了第一步。所以这是谷歌登录页面 https://accounts.google.com/signin/v2/identifier?hl=en&flowName=GlifWebSignIn&flowEntry=ServiceLogin#identifier,它给了我一个文本字段和按钮。我这样做:

        HtmlPage page=client.getPage(url);
        client.waitForBackgroundJavaScript(10*1000);
        HtmlButton button=(HtmlButton)page.getElementsByTagName("button").get(0);
        DomElement login=page.getElementById("identifierId");
        login.setAttribute("value","superyegorius");
        HtmlPage page2=button.click();
        client.waitForBackgroundJavaScript(10*1000);
        
        //page.executeJavaScript("document.getElementById('identifierId').value='superyegorius'");
        //page.executeJavaScript("document.getElementsByTagName('button')[0].click()");
        //button.click();
        //client.waitForBackgroundJavaScript(10*1000);
        
        String content=page.asXml();//if I execute page2.asXml() it returns the same html
        new Explorer().writeFile("page.html",content+"\r\n\r\n\r\n",false);
        System.out.println(content);System.exit(1);

当我尝试查看 page.html 时,我将页面的 html 放在那里,它总是相同的。它既没有在输入或密码字段中插入登录名,也没有在按钮单击后出现。任何人都可以向我解释我做错了什么。

任何帮助appriciated!

0 个答案:

没有答案