title: Switching urls in HtmlUnit
body: <p>Is there any way to change the url with session in HtmlUnit?</p>
  
  <p>My case is like here below,</p>
  
  <ol>
  <li>Login to <a href="http://test.raja.com" rel="nofollow">http://test.raja.com</a> with credentials.</li>
  <li>Get page <a href="http://home.raja.com" rel="nofollow">http://home.raja.com</a>, it should get my home page as logged in. </li>
  </ol>
  
  <p>In browser this is perfectly fine. But in HtmlUnit, I can get only test.raja.com not homepage. I tried WebWindow, WebConnection, addCookie etc but nothing works. </p>
  
  <p>Found this in <a href="https://community.jboss.org/wiki/UsingTheHtmlUnitAPIWithJSFUnit" rel="nofollow">https://community.jboss.org/wiki/UsingTheHtmlUnitAPIWithJSFUnit</a></p>
  
  <blockquote>
    <p>Getting a new URL in the same browser session</p>
    
    <p>If you want to simulate the user typing a URL into the browser session
    or need to do a GET request for any other reason, you need to use the
    WebClient and JSFUnit's WebConversationFactory as in this example:</p>
    
    <p>JSFSession jsfSession = new JSFSession("/index.jsf"); WebClient
    webClient = jsfSession.getWebClient();
    webClient.getPage(WebConversationFactory.getWARURL() +
    "/myotherpage.jsf");</p>
    
    <p>JSFSession, JSFServerSession, and JSFClientSession will stay in sync
    with the WebClient and you can continue to use those objects normally.
    Also, the HttpSession will be the same because the WebClient will
    continue to set the JSESSIONID cookie.</p>
  </blockquote>
  
  <p>Is this possible in HtmlUnit itself? </p>
  
  <p>my sample code</p>
  
  <pre><code>final WebClient webClient = new WebClient();
  HtmlPage page = webClient.getPage("https://home.raja.com");     
  final List&lt;FrameWindow&gt; window = page.getFrames();
  final HtmlPage pageTwo = (HtmlPage) window.get(0).getEnclosedPage();//this is test.raja.com served via iframe
  HtmlForm form = pageTwo.getFormByName("login");
  HtmlInput userName = (HtmlTextInput)form.getInputByName("testone");
  HtmlInput password = (HtmlPasswordInput)form.getInputByName("testtwo");
  userName.setValueAttribute("guest");
  password.setValueAttribute("guest");
  HtmlInput submit = (HtmlSubmitInput)form.getInputByName("submit");
  HtmlPage pagethree = (HtmlPage)submit.click();
  page = webClient.getPage("https://home.raja.com");      //here it again goes for login page
  </code></pre>