From: Martin S. <mar...@bi...> - 2015-08-15 08:50:02
|
Does anyone know how to log into Google (Google Sites) using HtmlUnit? I have been using BrowserVersion.CHROME from HtmlUnit-2.18. Login is a two-step process involving two forms. The first form has just the email field and the ‘Next’ button. After entering an email address and clicking ‘Next’, the second form displays. This form has the password field and the ‘Sign in’ button to complete the login process. Here is the code I am using: |HtmlForm form= (HtmlForm) webpage.getElementById("gaia_loginform"); HtmlTextInput email= (HtmlTextInput) webpage.getElementById("Email"); email.setValueAttribute("MyEmailAddress"); HtmlSubmitInput nextButton= form.getInputByValue("Next"); newWebpage= clickElement(nextButton); |||webclient.waitForBackgroundJavaScriptStartingBefore(8000); |HtmlForm form2= (HtmlForm) newWebpage.getElementById("gaia_loginform"); HtmlPasswordInput password= (HtmlPasswordInput) newWebpage.getElementById("Passwd-hidden"); password.setValueAttribute("MyPassword"); HtmlSubmitInput signInButton= form2.getInputByValue("Sign in"); myGoogleSitesHomeWebpage= clickElement(signInButton); ||webclient.waitForBackgroundJavaScriptStartingBefore(8000);| |clickElement(nextButton) |does not advance to a second form with the ‘Sign in’ button. It has my Google Sites web page I am trying to log into and my email correctly set up in the second form, but still with the link showing ‘Next’. I also think the input elements id="Email” and id="Passwd-hidden” are wrong and should be id="Email-hidden” and id="Passwd”. Here are the relevant parts of the second form. |<form novalidate="" method="post" action="https://accounts.google.com/ServiceLoginAuth" id="gaia_loginform"> <input name="continue" type="hidden" value="https://sites.google.com/site/MyGoogleSitesHomePageAddress"/> <input id="Email" name="Email" placeholder="Enter your email" type="email" value="MyEmailAddress" spellcheck="false" autofocus=""/> <input id="Passwd-hidden" type="password" spellcheck="false" class="hidden"/> <input id="next" name="signIn" class="rc-button rc-button-submit" type="submit" value="Next"/> <input id="signIn" name="signIn" class="rc-button rc-button-submit" type="submit" value="Sign in"/> </form>| Could anyone tell me what I am doing wrong and show me the code I should be using to do the complete login process? Many thanks, that would help me so much! Martin Email: mar...@bi... Or mar...@us... |