title: XPath: Help in locating a specific element in a DOM scraped using HTMLUnit
body: <p>I am scraping a webpage using HTMLUnit and have collected a List of DOM nodes from the webpage.</p>
  
  <p>Inside each of these "company" DOM nodes is some data I want to scrape. For example I want the telephone number text from inside this node:</p>
  
  <p><b></b></p>
  
  <p>Now, this element would be a child of a div element which is in turn a child of another div element inside the company node. What would be the correct XPath line to access it? Here is my latest attempt which returned nothing.</p>
  
  <pre><code> List&lt;DomNode&gt; companies = (List&lt;DomNode&gt;) page.getByXPath("//li[@class='featured block twoblock    boxshadow']");
          for (int j = 0; j &lt; companies.size(); j++) {
  
              DomNode company = companies.get(j);
  
                  // retrieve telephone number
                  DomNode telephone = (DomNode) company.getByXPath(
                          "//li[@data-pvd-p='"+j+1+"']/div[@class='listingWrapper']/div[@class='itemInfo']/span[@class='tel']").get(0);
  </code></pre>
  
  <p>}</p>
  
  <p>Here is a sample of the HTML, what:</p>
  
  <pre><code>        &lt;li class="featured block twoblock boxshadow" data-pvd-p="3" data-pvd-c="0046176330000011028" data-pvd-et="sv" data-pvd-l="true"&gt;
  
      &lt;div class="listingWrapper" itemtype="http://schema.org/LocalBusiness" itemscope=""&gt;
          &lt;a href="/Craddock-Electrical-Services-Ltd/0046176330000011028/"&gt;&lt;/a&gt;
          &lt;div class="itemInfo"&gt;
              &lt;div class="tradeImage" itemprop="member" itemscope="" itemtype="http://schema.org/Organization"&gt;&lt;/div&gt;
              &lt;h2&gt;
                  &lt;a itemprop="name" href="/Craddock-Electrical-Services-Ltd/0046176330000011028/"&gt;&lt;/a&gt;
              &lt;/h2&gt;
              &lt;span class="tel" itemprop="telephone"&gt;&lt;/span&gt;
              &lt;div class="listLinks"&gt;&lt;/div&gt;
              &lt;div id="addressBar"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="itemInfo2"&gt;&lt;/div&gt;
          &lt;div class="clearLeft"&gt;&lt;/div&gt;
          &lt;ul class="features"&gt;&lt;/ul&gt;
          &lt;div class="clearLeft"&gt;&lt;/div&gt;
          &lt;p class="promo" itemprop="description"&gt;&lt;/p&gt;
      &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Here is the current state of my XPath code.</p>
  
  <pre><code>List&lt;DomNode&gt; companies = (List&lt;DomNode&gt;) page
                  .getByXPath("//li[contains(@class, 'featured block')]");
          for (int j = 0; j &lt; companies.size(); j++) {
  
              String url = "";
              DomNode company = companies.get(j);
              DomElement web = null;
  
              // retrieve name
              DomNode name = (DomNode) company.getByXPath("//a[@itemprop='name']").get(j);
  
              if (companiesLogged.contains(name.getTextContent().trim()) != true) {
                  companiesLogged.add(name.getTextContent().trim());
  
                  // retrieve telephone number
                  DomNode telephone = (DomNode) company.getByXPath("div[@class='listingWrapper']/div[@class='itemInfo']/span[@class='tel']").get(0);
  
  
                  // retrieve website
                  try{
                  web = (DomElement) company.getByXPath("div[@class='listingWrapper']/div[@class='itemInfo']" +
                          "/div[@class='listLinks']/a[@id='linkWebsite']").get(0);
                  } catch(IndexOutOfBoundsException e){
                      System.out.print(" (No Website) ");
                  }
  
                  try{
                  url = web.getAttribute("href");
                  } catch (IndexOutOfBoundsException e){
                      url = "N/A";
                  }
  
                  System.out.println(name.getTextContent().trim() + "   "
                          + telephone.getTextContent().trim()
                   +"   "+url.trim());
  
              } else {
                  System.out.println("Company already logged");
              }
          }
  </code></pre>