We are trying to "browse" Facebook using HtmlUnit.
We are able to login and fetch my "home page" as follows:
final URL url = new URL("http://www.facebook.com/login.php");
final HtmlPage loginpage = (HtmlPage)webClient.getPage(url);
final HtmlForm form = (HtmlForm)loginpage.getElementById("login_form");
form.getInputByName("email").setValueAttribute("me@mymail");
form.getInputByName("pass").setValueAttribute("mypass");
final HtmlPage homepage = form.getInputByValue("Login").click();
We are in trouble when we are trying to access the "profile page" as:
HtmlPage profilepage = homepage.getElementByAccessKey('2').click();
The element being clicked is an anchor:
<a href="http://www.facebook.com/profile.php?id=myid" accesskey="2">Profile</a>
The problem is that 'sometimes' the fetched html is 'partly' stored in homepage, rather than profilepage. What it means is: only a few JavaScript functions are found in profilepage and homepage then contains rest of the html code for the facebook profile page.
The problem can be reproduced (although, a few times, it may not happen).