title: Login Using HtmlUnit
body: <p>I am very very new to HtmlUnit. I want to  know do I am able to login to a site using htmlunit and perform some operations in the site for example I want to login to my office portal and to aplly a leave.</p>I  am using html unit and it shows some errors, is its possible to do with html unit or <strong>are there any other tools I can use for this purpose</strong>... <br/>Here is my code</p>
  
  <pre><code>final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);        
  webClient.setJavaScriptEnabled(true);
  webClient.getCookieManager().setCookiesEnabled(true);
  
  final HtmlPage page1 =  webClient.getPage("http://www.ccstechnologies.org/login.aspx/");
  final HtmlForm form = page1.getFormByName("form1");         
  final HtmlSubmitInput button =  form.getInputByName("BtnLogin");
  final HtmlTextInput textField =  form.getInputByName("Username");
  final HtmlPasswordInput pwd =  form.getInputByName("password");        
  textField.setValueAttribute("username");
  pwd.setValueAttribute("password");      
  
  final HtmlPage page2 =  button.getEnclosingForm().click();  
  String htmlBody = page2.getWebResponse().getContentAsString(); 
  
  System.out.println("Base Uri 1 : "+page1);
  System.out.println("Base Uri 2 : "+page2);
  
  webClient.closeAllWindows();
  </code></pre>
  
  <p>But when I print <code>page2</code> it shows only the login page's url, and it is not returning the homepage url. What could be the problem ?
  <br/></p>
  
  <p>This is what I got in my console when clicked on form</p>
  
  <blockquote>
    <p>May 28, 2012 11:44:15 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
    WARNING: Obsolete content type encountered:'application/x-javascript'.
    May 28, 2012 11:44:16 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
    WARNING: Obsolete content type encountered: 'application/x-javascript'. 
    Base Uri 1 : HtmlPage(http://www.ccstechnologies.org/login.aspx/)@2741851 
    Base Uri 2 : HtmlPage(http://www.ccstechnologies.org/login.aspx/)@2741851</p>
  </blockquote>
  
  <p>results generated when clicked on button</p>
  
  <pre><code>May 29, 2012 10:00:02 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:02 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'application/x-javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
  WARNING: Obsolete content type encountered: 'text/javascript'.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
  WARNING: CSS error: [259:24] Error in expression. Invalid token "=". Was expecting one of: &lt;S&gt;, &lt;COMMA&gt;, "/", &lt;PLUS&gt;, "-", &lt;HASH&gt;, &lt;STRING&gt;, ")", &lt;URI&gt;, "inherit", &lt;EMS&gt;, &lt;EXS&gt;, &lt;LENGTH_PX&gt;, &lt;LENGTH_CM&gt;, &lt;LENGTH_MM&gt;, &lt;LENGTH_IN&gt;, &lt;LENGTH_PT&gt;, &lt;LENGTH_PC&gt;, &lt;ANGLE_DEG&gt;, &lt;ANGLE_RAD&gt;, &lt;ANGLE_GRAD&gt;, &lt;TIME_MS&gt;, &lt;TIME_S&gt;, &lt;FREQ_HZ&gt;, &lt;FREQ_KHZ&gt;, &lt;DIMENSION&gt;, &lt;PERCENTAGE&gt;, &lt;NUMBER&gt;, &lt;FUNCTION&gt;, &lt;IDENT&gt;.
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
  WARNING: CSS error: [259:29] Error in style rule. Invalid token "\r\n   ". Was expecting one of: "}", ";".
  May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
  WARNING: CSS warning: [259:29] Ignoring the following declarations in this rule.
  HtmlPage(http://192.168.0.5/login.aspx)@23511316
  HtmlPage(http://192.168.0.5/login.aspx)@17700115
  </code></pre>