简体   繁体   中英

xPath on HtmlTableRow (HtmlUnit) does not work properly

I am using getFirstByXPath on a HtmlTableRow with HtmlUnit, but it does not work properly.

If i log the HtmlTableRow asXml()

<tr class="odd">
  <td class="picColumn">
    <img src="xyz.jpg"/>
  </td>
  <td>

            Half Day Tour to the Rhine - Halbtages-Ausflug zum Rhein

  </td>
  <td>
    <b>
      Frankfurt am Main
    </b>
    <br/>

            ETS Gmbh &amp; Co. KG

  </td>
  <td class="dateColumn">

            01.04.2016
    <br/>

            15:15 Uhr

  </td>
  <td>
      Ticket
    </a>
  </td>
</tr>

Then I am trying to access different values with row.getFirstByXPath(xpath); which is only in following case fine: row.getFirstByXPath("//td[@class='dateColumn']"); . If I try to access the second column with row.getFirstByXPath("//td[2]"); my result is null. What am I doing wrong?

Thank you!

//td[2] should work on the XML you provided, so this is strange. Can you try (//td)[2] ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM