首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >XPath选择器在FirefoxDriver中工作得很好,但是不使用HtmlUnitDriver

XPath选择器在FirefoxDriver中工作得很好,但是不使用HtmlUnitDriver
EN

Stack Overflow用户
提问于 2011-03-29 13:06:24
回答 2查看 971关注 0票数 0

我的html页面中有下面的代码。

代码语言:javascript
运行
复制
<tr id="HL1035569648A" bgcolor="#ffffff">

  <td rowspan="2" align="center" width="40"><input name="product_id" value="1035569648" onclick="syncSA(this,document.inquiry.toggleSA);hlChecked(this,document.inquiry.product_id,2,'#ffffff');" type="checkbox"></td>


  <td rowspan="2" width="90"> <div id="ysop"><a href="http://www.globalsources.com/gsol/I/Induction-cooker/p/sm/1035569648.htm"><img class="imgborder" src="http://akamai.globalsources.com.edgesuite.net/f/593/3445/5d/pdt.static.globalsources.com/IMAGES/PDT/THUMB/648/T1035569648.jpg" alt="Induction Cooker Manufacturers" title="Induction Cooker Manufacturers" onmouseout="showPPOut();" onmouseover="showPPSummary(event,'1035569648',false,rollOvInqURL);" align="left" height="80" hspace="1" vspace="1" width="80"></a> </div></td>

  <td><a href="http://www.globalsources.com/gsol/I/Induction-cooker/p/sm/1035569648.htm" name="1035569648">Induction <b>Cooker</b></a><br>
Induction Cooker with 50/60Hz Rated Frequency, 90 to 230V AC Input Voltages and 7.2kW Maximum Power<br></td>

  <td><a href="http://inductioncooktop.manufacturer.globalsources.com/si/6008838306671/Homepage.htm" title="TOPBAND Induction cookers Division">TOPBAND Induction cookers Division</a><br><a href="http://inductioncooktop.manufacturer.globalsources.com/si/6008838306671/Showroom/3000000149681/ALL.htm">47&nbsp;products</a></td>


  <td rowspan="2">China (mainland)</td>
  <td rowspan="2">
        <div class="space_filler"><a href="javascript:actionInqSingleInqPath('/gsol/GeneralManager?&amp;catalog_id=2000000003844&amp;design=clean&amp;language=en&amp;action=GetInquireNowBasket&amp;page=inquiry/InqForm&amp;template=RFI&amp;inqflow_path=NLI','InquireNow_KW',1035569648)"><img src="http://akamai.globalsources.com.edgesuite.net/f/593/3445/5d/static.globalsources.com/gsol/en/clean/images/ICON-INQUIRE.GIF" border="0" height="13" width="55"></a></div>
        <div class="space_filler"><a href="javascript:void(0);" onclick="javascript:checkIM('/gsol/GeneralManager?&amp;catalog_id=2000000003844&amp;design=clean&amp;language=en&amp;page=im/IMSelection&amp;id=6008838306671&amp;IMSource=productsearch',340,455,'pop',null);"><img src="http://akamai.globalsources.com.edgesuite.net/f/593/3445/5d/static.globalsources.com/gsol/en/clean/images/ICON-CHAT.GIF" alt="Chat with this supplier (Login/Registration required)" title="Chat with this supplier (Login/Registration required)" border="0" height="13" width="55"></a></div>
  </td>
</tr>`

我要检索链接和描述

代码语言:javascript
运行
复制
<td><a href="http://www.globalsources.com/gsol/I/Induction-cooker/p/sm/1035569648.htm" name="1035569648">Induction <b>Cooker</b></a><br>
Induction Cooker with 50/60Hz Rated Frequency, 90 to 230V AC Input Voltages and 7.2kW Maximum Power<br></td>`

我正在使用下面的XPath:

代码语言:javascript
运行
复制
//Link: http://www.globalsources.com/gsol/I/Induction-cooker/p/sm/1035569648.htm
driver.findElements(By.xpath("//tr[starts-with(@id, 'HL')]/td[3]/a");

//Summary: Induction Cooker with 50/60Hz Rated Frequency, 90 to 230V AC Input Voltages and 7.2kW Maximum Power
driver.findElements(By.xpath("//tr[starts-with(@id, 'HL')]/td[3]");

注意:我不能使用HL1035569648A id ,因为有许多表行具有这个链接,而且所有表行都有不同的类名,但它们都以HL.开头。

这在FirefoxDriver中很好,但不适用于HtmlUnitDriver。任何人都能帮我。我不明白这个问题。

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2011-04-07 18:19:19

不惜一切代价避免XPATH定位器!

您可以很好地使用css : trid^='hl‘td:eq(2) a

但是,希望您不需要这个中间位,只需做一些类似trid^='hl‘a之类的事情。

票数 0
EN

Stack Overflow用户

发布于 2015-06-11 06:36:38

试试这个:

代码语言:javascript
运行
复制
//tr[contains(@id,"HL")]/td[3]/a
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5472983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档