title: Unable to get element with id from a URL using HtmlUnit in Java
body: <p>Unable to get element with <code>id="parcelMailingAddressResult"</code> from <code>https://www.mohavecounty.us/ContentPage.aspx?id=111&amp;cid=869&amp;parcel=10272001</code> using <code>HTMLUnit</code> in <code>Java</code></p>
  
  <p>If you go to above URL , you will see that there is a mailing address. A DOM inspection of the website shows that address has the above mentioned ID. I have been trying for several days to get that mailing address using my Java/HTMLUnit, and none of my tries worked.<br><br>
  Below are three methods that I tried within the same code.</p>
  
  <pre><code>System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
  final WebClient webClient = new WebClient();
  webClient.getOptions().setCssEnabled(false);
  webClient.getOptions().setJavaScriptEnabled(false);           
  webClient.getOptions().setThrowExceptionOnScriptError(false);
  webClient.setRefreshHandler(new RefreshHandler() {
  public void handleRefresh(Page page, URL url, int arg) throws IOException {
      System.out.println("handleRefresh");
  }
  });
  HtmlPage page = (HtmlPage) webClient.getPage("https://www.mohavecounty.us/ContentPage.aspx?id=111&amp;cid=869&amp;parcel=10272001"); 
  DomElement ownerAddresses = page.getElementById("parcelMailingAddressResult");
  NodeList nodes = page.getElementsByTagName("parcelMailingAddressResult");
  final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@class='container-fluid row']").get(0);
  </code></pre>
  
  <p>I expected the variables <code>ownderAddresses</code> and nodes to contain information that includes the owner's address. I expect <code>div</code> to contain some other information and, once I changed <code>get(0)</code> to <code>get(&lt;someHigherInteger&gt;)</code>, to contain also information about the owner's address.</p>
  
  <p><strong>Instead:</strong><br></p>
  
  <ol>
  <li><code>ownerAddresses = null</code> (after execution of ownerAddress = ...)</li>
  <li>nodes is of size 0 (after execution of nodes = ...)</li>
  <li><code>final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@class='container-fluid row']").get(0);</code>
  after about 13 seconds, throws the following exception:</li>
  </ol>
  
  <p><strong>Exception:</strong><br>
  <code>java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0</code>.</p>
  
  <p>which means that <code>(HtmlDivision) page.getByXPath("//div[@class='container-fluid row']")</code> was of length 0.</p>