简体   繁体   English

HtmlTableRow(HtmlUnit)上的xPath无法正常工作

[英]xPath on HtmlTableRow (HtmlUnit) does not work properly

I am using getFirstByXPath on a HtmlTableRow with HtmlUnit, but it does not work properly. 我在具有HtmlUnit的HtmlTableRow上使用getFirstByXPath,但无法正常工作。

If i log the HtmlTableRow asXml() 如果我登录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); 然后我尝试使用row.getFirstByXPath(xpath);访问不同的值row.getFirstByXPath(xpath); which is only in following case fine: row.getFirstByXPath("//td[@class='dateColumn']"); 仅在以下情况下可以使用: row.getFirstByXPath("//td[@class='dateColumn']"); . If I try to access the second column with row.getFirstByXPath("//td[2]"); 如果我尝试使用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. //td[2]应该可以在您提供的XML上工作,所以这很奇怪。 Can you try (//td)[2] ? 您可以尝试(//td)[2]吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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