AbdenourAchab · GitHub

I am trying to get to the docSearch form of the https://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jsp web page using the latest HTMLUnit release (2.37.0). As you can see using Firefox's DOM Inspector, there is such a form
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_68); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.setJavaScriptErrorListener(new SilentJavaScriptErrorListener()); HtmlPage page = webClient.getPage("https://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jsp"); webClient.waitForBackgroundJavaScriptStartingBefore(1000000000); page = (HtmlPage) page.getEnclosingWindow().getEnclosedPage(); HtmlForm form = page.getFormByName("docSearch");

The last line of the above code gives me the following exception:
com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[form] attributeName=[name] attributeValue=[docSearch]

This issue was discussed and investigated at
https://stackoverflow.com/questions/60148335/com-gargoylesoftware-htmlunit-elementnotfoundexception-elementname-form-attri?noredirect=1#comment106625029_60148335

But it was NOT solved in those discussions and investigations.

Here is a summary of what we found out:

  1. docSearch does not show up in page.asXml()
  2. There are two forms in https://eagletw.mohavecounty.us/treasurer/treasurerweb/search.jsp , and page.getForms() does return two forms. But the second form (the one of interest here) doesn't work. Each of the following pieces of code results in an exception:
    2.a)
    HtmlForm form = page.getForms().get(1); HtmlInput hi = form.getInputByValue("Search");
    results in the following exception: com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[value] attributeValue=[Search]
    2.b) HtmlForm form = page.getForms().get(1); List<HtmlInput> his = form.getByXPath("//input[@value='Search']"); Iterator hisIterator = his.iterator(); HtmlInput hi = (HtmlInput) hisIterator.next();
    results in the following exception: java.util.NoSuchElementException

Read the original on github.com ↗