Html 正确使用xpath轴定位
我正在测试一个带有动态ID的网页。该页面在多个位置包含一个删除图标和一个浏览图标,我无法单击这些图标,或者我必须说我无法编写正确的XPath来定位任何特定图标 下面是HTML代码的一个片段Html 正确使用xpath轴定位,html,xpath,selenium,selenium-webdriver,Html,Xpath,Selenium,Selenium Webdriver,我正在测试一个带有动态ID的网页。该页面在多个位置包含一个删除图标和一个浏览图标,我无法单击这些图标,或者我必须说我无法编写正确的XPath来定位任何特定图标 下面是HTML代码的一个片段 <tr class="tableNestedAttribute"> <td class="autosuggest-svl-cell"> <input name="odf_obs_fin_dept_text"> <div id="
<tr class="tableNestedAttribute">
<td class="autosuggest-svl-cell">
<input name="odf_obs_fin_dept_text">
<div id="div_d31505e760_location"></div>
</td>
<td class="actions" nowrap="" align="right">
<div class="ui-browse-lookup-images ppm_field formFieldDisNoWidthReadOnly ">
<img id="d31505e7601" title="Remove Department OBS" name="Remove">
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
</div>
</td>
</tr>
在提供的示例中,使用以下XPath:
//input[@name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/div/img[@name='Browse']
将找到下一个元素:
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
//*[@name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/descendant::div/img[@name='Browse']