【发布时间】:2017-09-04 03:49:12
【问题描述】:
我收到以下异常,
无效的选择器:无法使用 xpath 定位元素 表达式 //select[@name='countryList 因为以下错误: SyntaxError:无法对“文档”执行“评估”:字符串 '//select[@name='countryList' 不是有效的 XPath 表达式。
这是我的html代码,
<form method="post" action="/eClaims/app" name="itemEditForm" id="itemEditForm" class="itemEditForm" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="formids" value="TextField,wdd">
<input type="hidden" name="component" value="ClaimItemDetail.itemEditForm">
<input type="hidden" name="page" value="ClaimItemPage">
<input type="hidden" name="service" value="direct">
<input type="hidden" name="session" value="T">
<input type="hidden" name="If_87" value="T">
<input type="hidden" name="For_3" value="ecfqwcqw">
</div>
<input type="text" name="TextField" value="" id="requestKeyItemId" style="visibility: hidden">
<!-- START ORDERED Item detail table -->
<div name="mainClaimItemDetailDiv">
<table width="100%" bgcolor="#cccccc">
</table>
<!-- show item information section START -->
<table width="100%" bgcolor="#cccccc">
<tbody><tr bgcolor="silver">
<th>
HP Item Ref.
</th>
<th>
Estimated Value
(
AUD
)<br>
</th>
<th>
Country of Origin
</th>
<th>
Serial #
</th>
<th>
Estimated Value($)
</th>
<th>
<input type="text" name="clmid" value="" id="clmid" style="visibility: hidden;">
</th>
</tr>
<tr width="100%" bgcolor="#cccccc">
<td align="center">
56730270
</td>
<td>
252.79
</td>
<td align="center">
<!--<span jwcid="countryList_1" onchange="javascript:checkIfDropdownValueNull(this);" ></span> -->
<select name="countryList_1" id="countryList_1" style="width:50px;">
<option value="">--please select--</option>
<option value="AF">AF</option>
<option value="ZW">ZW</option>
</select>
</td>
<td align="center">
<input type="text" name="serialNo_2" value="5CD6340S04" id="serialNo_2" maxl="10" onfocus="javascript:onProductFocus(this);" size="10" onblur="javascript:onItemDataChange(this,10)">
</td>
<td align="center">
187.06
</td>
<td align="center">
<input type="submit" name="Submit" id="fetchitemBtn" class="fetchitemBtn" style="visibility: hidden;">
</td>
</tr>
</tbody></table>
</form>
到目前为止,我使用了以下定位器,
//select[contains(@id,'countryList_1')]
//select[@id,'countryList_1']
//**[@id="itemEditForm"]/div[@name='mainClaimItemDetailDiv']/table[2]/tbody/tr[2]/td[11]
//**[@id="itemEditForm"]/div[@name='mainClaimItemDetailDiv']/following::select[@id='countryList_1']
虽然,最后一个 xpath 没有定位任何元素。 我用了很多,但都无济于事。
请帮忙。
提前致谢
【问题讨论】:
-
//select[@id='countryList_1']将找到一个 id = 'countryList_1' 的下拉列表。我已经在你的 HTML 上检查了它,它工作正常。检查拼写错误。 -
我认为你的 xpath 有语法错误
-
你的问题解决了吗?
-
是的,使用了以下 xpath :
-
//*[@id="itemEditForm"]/div[@name='mainClaimItemDetailDiv']/table[2]/tbody/tr[2]/td[11]/select跨度>