From: Ronald B. <rb...@rb...> - 2015-08-15 10:12:11
|
Hi Martin, have not done a detailed analysis but some hints: * use FF38 instead of Chrome, the FF simulation is the most complete one at the moment * it's not that uncommon for todays web apps that clicking a button does not directly return the new page (thanks AJAX). You already did some wait after the click, but you have to get the current content/page after the wait for doing the next steps (use WebWindow#getEnclosedPage); this wait stuff is the most tricky part of driving moder web applications.... * have a look at the log output and search for js errors - if you are facing such errors please report them to the html unit bug tracker (have a look at http://htmlunit.sourceforge.net/submittingBugs.html and http://htmlunit.sourceforge.net/submittingJSBugs.html before) Hope that helps a bit RBRi -------------------------- WETATOR Smart web application testing http://www.wetator.org On Sat, 15 Aug 2015 18:19:50 +0930 Martin Strange wrote: > >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... > > > > >----< Inline text [text-plain-04.txt] >------------------ > >------------------------------------------------------------------------------ > > > >----< Inline text [text-plain-05.txt] >------------------ > >_______________________________________________ >Htmlunit-user mailing list >Htm...@li... >https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > |