I am writing a program in Java using Htmlunit that has a Radio Button that needs to be clicked to fill out a set of information. I am currently having an issue finding the fields that need to be entered after the radio button is clicked. Currently my code is:
String url = "http://cpdocket.cp.cuyahogacounty.us/";
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
final HtmlForm form = page.getForms().get(0);
final HtmlElement button = form.getElementById("SheetContentPlaceHolder_btnYes");
final HtmlPage page2 = button.click();
try {
synchronized (page2) {
page2.wait(3000);
}
}
catch(InterruptedException e)
{
System.out.println("error");
}
//returns the first page after the security page
final HtmlForm form2 = page2.getForms().get(0);
final HtmlRadioButtonInput button2 = form2.getInputByValue("forcl");
button2.setDefaultChecked(true);
page2.refresh();
final HtmlForm form3 = page2.getForms().get(0);
form3.getInputByName("ctl00$SheetContentPlaceHolder$foreclosureSearch$txtZip").setValueAttribute("44106");
final HtmlSubmitInput button3 = form3.getInputByValue("Submit");
final HtmlPage page3 = button3.click();
try {
synchronized (page3) {
page2.wait(10000);
}
}
catch(InterruptedException e)
{
System.out.println("error");
}
While the first page is a security page that needs to be bypassed, the second page is where I am running into the issue as I am getting the error "
com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[name] attributeValue=[ctl00$SheetContentPlaceHolder$foreclosureSearch$txtZip]
at com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName(HtmlForm.java:463)
at Courtscraper.scrapeWebsite(Courtscraper.java:58)"
I believe this means that the input field cannot be found in the form. I have been referring to two websites as reference. Website1, Website2. I am not sure, but i believe I may have to create a new HtmlPage after setting the radio button to true.