【发布时间】:2015-10-04 11:11:49
【问题描述】:
我正在尝试从 HTML 表格中显示的一系列频道中选择一个频道。我正在使用以下 Selenium 方法来选择链接
WebElement channel = driver.findElement(By.xpath("//span[contains(text(),Sales)]"));
channel.click();
但是,它选择了列表中的第一个频道(帐户管理)。我希望它要么选择正确的通道,要么抛出错误,而不是选择错误的通道。以下是我想要的频道的完整xpath:
/html/body/div[2]/div[2]/form/div/table/tbody[2]/tr/td/ul/li[2]/a/span
频道列表在 HTML 代码中是这样定义的:
<form action="nextpage.do" method="post" name="selectChannelForm">
<div class="de">
<h2>Select channel</h2>
<table id="selectChannelForm">
<tbody id=""></tbody>
<tbody id="">
<tr rowtype="container">
<td class="desecond" colspan="3">
<ul>
<li>
<a id="selected_a" href="nextpage.do?selectedChannel=123">
<span>Account Management</span></a>
</li>
<li>
<a id="selected_a" href="nextpage.do?selectedChannel=456">
<span>Sales</span></a>
</li>
<li>
<a id="selected_a" href="nextpage.do?selectedChannel=789">
<span>Complaints</span></a>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<input type="hidden" value="selectChannelForm" name="formid">
</div>
【问题讨论】:
标签: java html selenium xpath xquery