title: Click a Html Button using HtmlUnit in Java
body: <p>I am currently developing a system. I need to click a website button using Java. So I am using <strong>HtmlUnit</strong> Library. There is a website called <a href="https://tempmail.ninja/" rel="nofollow noreferrer">https://tempmail.ninja/</a> that generates temporary emails. What I need is program to click the Generate button in <strong>tempmail.ninja</strong> and it generates a temporary email. But the problem is it is not clicking. Not generating the email.</p>
  
  <p>Here is my code What I have tried, </p>
  
  <pre><code>    try
      {
         WebClient webClient = new WebClient(BrowserVersion.CHROME);
         webClient.getOptions().setCssEnabled(true);
         webClient.getOptions().setJavaScriptEnabled(true);
         webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
         webClient.getOptions().setThrowExceptionOnScriptError(false);
         webClient.getOptions().setUseInsecureSSL(true);
         webClient.getCookieManager().setCookiesEnabled(true);
         HtmlPage page = webClient.getPage("https://tempmail.ninja");
  
         //Here is button id. Instead of this I used HtmlAnchor, HtmlSubmitInput and etc.
         //But any of those didn't work         
         HtmlButton htmlButton = page.getHtmlElementById("generaEmailTemporal");
         htmlButton.click();
  
         webClient.waitForBackgroundJavaScript(5000 * 2);   
  
         //Print the generated email but Currently nothing display
         HtmlTextInput htmlTextInput = (HtmlTextInput) page.getElementById("emailtemporal");
         System.out.println(htmlTextInput.getText());
  
         webClient.close();
  
      } catch(ElementNotFoundException | FailingHttpStatusCodeException | IOException ex) {
         Logger.getLogger(WebTesting.class.getName()).log(Level.SEVERE, null, ex);
      }
  </code></pre>
  
  <p>Here is the HTML code for the button. I get this using Inspect Element. </p>
  
  <pre><code>&lt;p class="text-center" id="btnGeneraEmailTemporal"&gt;
  &lt;button class="btn btn-labeled btn-primary" id="generaEmailTemporal" type="button"&gt;
  &lt;span class="btn-label"&gt;&lt;i class="fa fa-hand-o-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/span&gt; Generate Temp Mail
  &lt;/button&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I am newbie to HtmlUnit. So Can anybody help me? I really appreciate that.
  Thanks for your Help. </p>