I've been testing HtmlUnit with a few sites; in all these sites,they have elements such as a radio button or checkbox that when you click, then your profile on that site is updated; you don't need to submit a form or anything. But when I take the exact same actions with HtmlUnit, my profile on the server is not really updated. Do I have to do something special such as synchronizing the local copy of the page that HtmlUnit has with the server so that the server sees the change? As an example, I have added my code for switching my resume on a website from private/public and vice versa. When I visit the page on a browser, all I have to do is click one of the two radio buttons to make the resume public/private; but when I do the same on HtmlUnit, and then go and visit the page on a browser to check, I can see that the information on the server hasn't been changed. I've included my code below. Note that I have another method which logs in to the site, and I know that I login correctly. Given this is happening with my sites for me, I thought maybe there is something like synchronizing with the server that I'm not doing.
=====================================
public void update(String urlOfThePage)
{
// First, declare any element name or xapth that you are going to
use. String xpathOfIsPublicRadioButton = "//input[@id='privacy_show']";
String xpathOfIsPrivateRadioButton = "//input[@id='privacy_hide']";
// Get the first page
try
{
final HtmlPage resumePage = (HtmlPage) webclient.getPage(urlOfThePage);
CrawlerUtility.savePage(resumePage, "resumePage");
final HtmlRadioButtonInput makePublicRadioButton =
(HtmlRadioButtonInput)
resumePage.getFirstByXPath(xpathOfIsPublicRadioButton);
final HtmlRadioButtonInput makePrivateRadioButton =
(HtmlRadioButtonInput)
resumePage.getFirstByXPath(xpathOfIsPrivateRadioButton);
Page result = null;
if (isProfilePublic())
{
result = makePrivateRadioButton.click();
System.out.println("The Profile is changed to private
now.");
Thread.sleep(60000);
}
else
{
result = makePublicRadioButton.click();
System.out.println("The Profile is changed to public now.");
Thread.sleep(60000);
}
}
catch (Throwable e)
{
e.printStackTrace();
}//End of try/catch block.
}//End of update().