I am trying to click a button on a website using HTMLUNIT i, following this guide http://htmlunit.sourceforge.net/gettingStarted.html , but this requires a form name. The website I'm trying to make has this source.
<form method="post" action="doDelete"> Are you sure you want to delete 'Apple?'? <input name="Submit" value="Yes" class="submit-button" type="submit" /> </form>
I am trying to click the Yes button check box on a web page. (Remove Valdation). As you can see, there is no form name. Here is my code.
final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage("http://ma.some-site.com:8080/user/mike/delete"); List<HtmlForm> formlist = (List<HtmlForm>) page1.getForms(); System.out.println(formlist.toString()); final HtmlForm form = page1.getFormByName("myform"); <---Problem here final HtmlSubmitInput button = form.getInputByName("Submit"); button.click(); webClient.closeAllWindows();
I tried this but did not work
final HtmlForm form = page1.getFormByName(formlist.get(1).getLocalName());
I believe you can use xpath to find the name of the form?
source share