Note that there are some explanatory texts on larger screens.

plurals
  1. POHTMLUnit not clicking a button
    text
    copied!<p>I have a simple HTML unit code that is used to press a button and submit a form on a page, but it doesn't want to work. This is my code: </p> <pre><code> public static boolean sub(String ref, String zip) throws Exception { WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setJavaScriptEnabled(true); webClient.getCookieManager().setCookiesEnabled(true); final HtmlPage page1 = webClient.getPage("http://site.com/"); webClient.waitForBackgroundJavaScript(20000); final HtmlButton button = page1.getFirstByXPath("//*[@id=\"lookup\"]"); final HtmlTextInput orderField = page1.getFirstByXPath("//*[@id=\"order-number\"]"); final HtmlTextInput zipField = page1.getFirstByXPath("//*[@id=\"order-user-info\"]"); orderField.setValueAttribute(ref); zipField.setValueAttribute(zip); final HtmlPage page2 = button.click(); webClient.waitForBackgroundJavaScript(20000); System.out.println(page2.asText()); webClient.closeAllWindows(); return true; } </code></pre> <p>All this does is print out the text of the first page, but with the text boxes filled in. As you can see, I tried waiting for javascript, it still doesn't work. Any help is appreciated.</p> <p>UPDATE: I found at some new info. It seems that when I enter an order number that is correct, it just shows the current page with the text boxes filled in, instead of the page it is suposed to redirect to, but when I enter wrong info, it shows the current page with the text boxes filled in AND the "Wrong Info" error message. It seems that this is just not redirecting...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload