title: HtmlUnit - Button click issues
body: <p>I am coding up a server in java, and for part of the server I need a webscraper. To scrape the website, I need to log in and the web scraper works perfectly when running as a main method, but when ran on the server, the button click does not redirect to a new page. Here is the code.</p>
  
  <pre><code>    String loginUrl="MY_URL";
      WebClient web = new WebClient();
      WebClientOptions options=web.getOptions();
      web.getCookieManager().setCookiesEnabled(true);
      options.setJavaScriptEnabled(true);
      options.setPrintContentOnFailingStatusCode(false);
      options.setCssEnabled(false);
      options.setThrowExceptionOnFailingStatusCode(false);
      options.setThrowExceptionOnScriptError(false);
      options.setRedirectEnabled(true);
      try {
          final HtmlPage firstPage = (HtmlPage)web.getPage(loginUrl);
          final HtmlForm form = firstPage.getForms().get(0);
          final HtmlTextInput userNameField = form.getInputByName("USER");
          userNameField.setValueAttribute("MY_USERNAME");
          final HtmlPasswordInput passWordField = form.getInputByName("PASSWORD");
          passWordField.setValueAttribute("MY_PASSWORD");
          HtmlButton button =(HtmlButton)firstPage.getElementById("safeLoginbtn");
          System.out.println(firstPage.getUrl().toString());
          button.click();
          System.out.println(web.getEnclosedPage().getUrl().toString());
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>When running this in a main method, the two print statements show two different pages, the log in page and the page behind the log in respectively. But when running on a server, the two print statements have nearly the same url, and both are urls for the log in page. Why could this be happening? Why does the code act differently in a main method compared to being run on the server?</p>
  
  <p>The server is being run by a Spring framework if that has any thing to do with it. </p>
  
  <p>EDIT:
  Example here:</p>
  
  <pre><code>    WebClient webClient = new WebClient();
      HtmlPage page1 = webClient.getPage("http://www.facebook.com");
      HtmlForm form = page1.getForms().get(0);
      HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0);
      HtmlTextInput textField = form.getInputByName("email");
      textField.setValueAttribute("email@email.com");
      HtmlPasswordInput textField2 = form.getInputByName("pass");
      textField2.setValueAttribute("MY_PASS");
      HtmlPage page2 = button.click();
      System.out.println(page2.asText());
  </code></pre>
  
  <p>This works in a main method of a java application, but when run on the server by Spring's scheduled annotation, it will not log me in.</p>