AbdenourAchab · GitHub

If you go to https://parcelinquirytreasurer.cochise.az.gov/ , type 3020702601 in the text field and click on Submit, you will see $514.20 at the (4,6) position in a table. If you click on that $514.20, you will get a new page that has a new table. In you inspect any element of that table, you will see that it has role="treegrid".

I am trying, and so far failing, to access, using HtmlUnit 4.7.0, the table with role="treegrid".

Below is my code in JDK 24, Apache Netbeans 25 (a single Java file):

package cochise3020702601;
import java.util.*;
import org.htmlunit.*;
import org.htmlunit.html.*;
public class Cochise3020702601 {
    public static void main(String[] args) {
	try (final WebClient webClient = new WebClient(BrowserVersion.FIREFOX)) {
            webClient.getOptions().setCssEnabled(false);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            HtmlPage page = webClient.getPage("https://parcelinquirytreasurer.cochise.az.gov/");
            webClient.waitForBackgroundJavaScriptStartingBefore(10_000);
            page = (HtmlPage) page.getEnclosingWindow().getEnclosedPage();
            List<HtmlForm> forms = page.getByXPath("//form[@method='post']");
            Iterator<HtmlForm> formsIterator = forms.iterator();
            HtmlForm form = formsIterator.next();
            List<HtmlInput> his = form.getByXPath("//input[@value='Submit']");
            Iterator<HtmlInput> hisIterator = his.iterator();
            HtmlInput hi = hisIterator.next();
            HtmlTextInput textField = form.getInputByName("parcelNumber_input");
            textField.type("3020702601");
            HtmlPage page2 = hi.click();
            webClient.waitForBackgroundJavaScriptStartingBefore(10_000);
            List<HtmlTable> accountTables = page2.getByXPath("//table[@role='grid']");
            Iterator accountTablesIt = accountTables.iterator();
            HtmlTable accountTable = (HtmlTable) accountTablesIt.next();
            List<HtmlElement> clickables = accountTable.getCellAt(5,5).getByXPath("//a[@class='gridlink']");
            Iterator clicks = clickables.iterator();
            HtmlElement he2 = (HtmlElement) clicks.next();
            HtmlPage page3 = (HtmlPage) he2.click();
            webClient.waitForBackgroundJavaScriptStartingBefore(10_000_000);
            page3 = (HtmlPage) page3.getEnclosingWindow().getEnclosedPage();
            webClient.waitForBackgroundJavaScriptStartingBefore(10_000_000);
            System.out.println("page3.asXml() = " + page3.asXml());
            List<HtmlElement> hts = page3.getByXPath("//a[@role='treegrid']");
            System.out.println("hts.size() = " + hts.size());
            System.out.println("----------------------------------------------");
	}
	catch (Exception e) {
            System.out.println("Exception:  " + e.toString());
	}
    }
}

In the page3.asXml() printout, I do see some expected information, such as "Payment History". But I don't see any table with a treegrid role.

I was expecting hts.size() to return at least 1. Instead, the printout I get is hts.size() = 0

Read the original on github.com ↗