When I try to run the program everything works except clicking the button. When I click the button I get this exception: java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlButtonInput cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlSubmitInput
public class Connect {
public Connect(int port, String host) {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3/*, host, port*/);
webClient.setJavaScriptEnabled(true);
HtmlPage page = null;
try {
page = webClient.getPage("localhost/vote.php");
} catch (IOException e) {
e.printStackTrace();
}
HtmlForm button = page.getFormByName("voted");
HtmlSubmitInput formSubmit = button.getInputByName("reward");//errors: java.lang.ClassCastException: com.gargoylesoftware.htmlunit.html.HtmlButtonInput cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlSubmitInput
page.executeJavaScript("setStatus(1);");
page.executeJavaScript("setStatus(2);");
page.executeJavaScript("setStatus(3);");
page.executeJavaScript("canClickReward = true;");
try {
formSubmit.click();
} catch (IOException e) {
System.out.println("Form Button" + e.getMessage());
}
//page.executeJavaScript("document.forms[\"voted\"].submit()"); //Doesn't submit form
System.out.println(page.asText());
}
}
Does anyone know how I could fix the cast issue so it will click the button in the form?
Change the line
to
The first line would work if your HTML had
But apparently it has