问题描述
我处于一种奇怪的情况,我的行中有多个具有相似值的行,我需要选择在第一个单元格中与文本Protractor"和在同一行的第二个单元格中具有文本NewAge"链接的元素.
I am in a weird situation where I have multiple rows with similar values in my rows and I need to select element which has link with text "Protractor" in first cell and text "NewAge" in second cell of same row.
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="resultsTable"><tr><td>
<a href = "Mytitle.aspx">Protractor</a>
<td>NewAge</td>
</tr>
<tr><td>
<a href = "NewMytitle.aspx"> NewProtractor </a>
<td>NewAge</td>
</tr>
<tr><td>
<a href = "NewProtTile.aspx">Protractor</a>
<td>NewAge World</td>
</tr></table>
现在我希望根据第一个和第二个单元格中的文本值选择我的超链接元素,即Protractor"和NewAge"
Now I want my hyperlink element to be picked based on both text values in first and second cell which is 'Protractor' and 'NewAge'
我想使用精确文本搜索而不是包含文本,因为许多其他行具有相似的值
这是 Chrome 返回的 xpath.
I want to use exact text search instead of containing text as many other rows has similar values
This is the xpath returned by Chrome.
//*[@id="PageContent"]/table/tbody/tr[2]/td/table/tbody/tr[3]/td[1]/a
我尝试使用 xpath 在第一个单元格中选择文本为Protractor"的链接,在同一行的第二个单元格中选择NewAge",但没有获得所需的结果.
I tried using xpath to select the link with text as 'Protractor' in first cell and "NewAge" in second cell of same row but not getting an desired results.
element(by.xpath("//tr['Protractor']['NewAge']"))
有人可以帮忙吗?
推荐答案
基于 Protractor 的第一个和第二个单元格中的文本值识别/检索超链接元素
> 和 NewAge 您可以使用以下 xpath
:
To identify/retrieve the hyperlink element
based on both text values in first and second cell which is Protractor and NewAge you can use the following xpath
:
//table[@class='resultsTable']//td[text()='NewAge']//preceding::a[text()='Protractor']
这篇关于根据表格量角器中的两个单元格值查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!