title: HtmlUnit infinite loop when redirect link after the form submit is same as the one containing form
body: <p>I am trying to login to a web page <a href="https://online.firstdata.de/esp/concardis/" rel="nofollow noreferrer">https://online.firstdata.de/esp/concardis/</a> using HTMLunit library in Java. The thing is that this page contains a form inside a couple of iframes. The source of the iframe containing the form is <a href="https://online.firstdata.de/login/postlogin/UserDispatcher" rel="nofollow noreferrer">https://online.firstdata.de/login/postlogin/UserDispatcher</a>
  . When a form is submitted then one of the redirect links before the next page is rendered is also the same link as mentioned above.
  So, this creates an infinite loop when I use it from Java. However, when the login happens from the browser because the main source of the originating page was the link ending with /concardis the redirect link is not the same as this link and hence there is no infinite loop. How can I simulate this same behaviour from Java? Here is my code :</p>
  
  <pre><code>WebClient webClient = new WebClient(BrowserVersion.CHROME);
  
      webClient.getOptions().setJavaScriptEnabled(true);
      webClient.getOptions().setRedirectEnabled(true);
      webClient.getOptions().setThrowExceptionOnScriptError(false);
      webClient.getOptions().setCssEnabled(false);    
      webClient.setAjaxController(new NicelyResynchronizingAjaxController());
  
  
      try{
  
  
          HtmlPage page1 = null;
          HtmlPage page2 = null;
          HtmlPage page3 = null;
           HtmlPage page = webClient.getPage("https://online.firstdata.de/esp/concardis");
  
  
  
  
          List&lt;FrameWindow&gt; frames = page.getFrames();
          for (FrameWindow frame : frames) {
              if (frame.getFrameElement().getNameAttribute().equals("application")) {
                  page1 = webClient.getPage(frame.getEnclosedPage().getUrl());
              }
          }
  
          List&lt;FrameWindow&gt; frames1 = page1.getFrames();
          for (FrameWindow frame : frames1) {
              if (frame.getFrameElement().getNameAttribute().equals("content")) {
                  page2 = webClient.getPage(frame.getEnclosedPage().getUrl());
              }
          }
  
          List&lt;FrameWindow&gt; frames2 = page2.getFrames();
          for (FrameWindow frame : frames2) {
              if (frame.getFrameElement().getId().equals("loginFrame")) {
                  page3 = webClient.getPage(frame.getFrameElement().getSrcAttribute());
              }
          }
  
  
          HtmlForm form = page3.getFormByName("loginForm");
          HtmlTextInput userName = form.getInputByName("j_username");
          HtmlPasswordInput password = form.getInputByName("j_password");
  
          userName.setValueAttribute("username");
          password.setValueAttribute("password");
  
          HtmlSubmitInput submit = form.getInputByName("Submit");
  
          submit.click();
  </code></pre>