XPath Selector Working fine with FirefoxDriver but not working with HtmlUnitDriver
I have below co开发者_StackOverflow社区de in my html page.
<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 products</a></td>
<td rowspan="2">China (mainland)</td>
<td rowspan="2">
<div class="space_filler"><a href="javascript:actionInqSingleInqPath('/gsol/GeneralManager?&catalog_id=2000000003844&design=clean&language=en&action=GetInquireNowBasket&page=inquiry/InqForm&template=RFI&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?&catalog_id=2000000003844&design=clean&language=en&page=im/IMSelection&id=6008838306671&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>`
I want to retrieve link and description
<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>`
I am using below XPath:
//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]");
Note: I cannot use HL1035569648A
full id
because there are many Table Rows having this links and all table rows has different class name but they all starts with HL.
This works fine with FirefoxDriver
but it is not working with HtmlUnitDriver
. Is anyone can help me. I am not understanding the issue.
thanks!
Avoid XPATH locators at all costs!
You can use css just fine: tr[id^='hl'] td:eq(2) a
However hopefully you don't need that middle bit and can just do something like tr[id^='hl'] a
Try this:
//tr[contains(@id,"HL")]/td[3]/a
精彩评论