如何根据柏树测试中另一个表数据元素的值访问表数据元素
在下面的HTML表中,我试图根据用户名(即john
)找到一行,&然后单击与该TR
记录关联的菜单
按钮:
<table>
<tr>
<td><a ng-click="onViewItemDetails(item, null, $event)">John</a></td>
<td><a>Smith</a></td>
<td><a><i class="activity-burger-menu">Menu</i></a></td>
</tr>
</table>
在伪代码中,应该是:
cy.getRecordBasedOnName('John).then(() => {
// After finding that record, click the button with this class, on that row
cy.get('.activity-burger-menu').click()
)
In the below HTML table, I am trying to find a row based on the user's name (i.e. John
), & then click the Menu
button associated with that tr
record:
<table>
<tr>
<td><a ng-click="onViewItemDetails(item, null, $event)">John</a></td>
<td><a>Smith</a></td>
<td><a><i class="activity-burger-menu">Menu</i></a></td>
</tr>
</table>
In pseudo-code it should be something like:
cy.getRecordBasedOnName('John).then(() => {
// After finding that record, click the button with this class, on that row
cy.get('.activity-burger-menu').click()
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了使用
兄弟姐妹
的解决方案I found this solution that uses
siblings
要查找带有特定文本的行,您需要使用
.contains。 (选择器,文本)
要找到该行,然后在行中搜索以查找要单击的菜单文本。注意:
.contains()
只会返回第一个匹配的DOM元素,因此,如果您有多个匹配名称,则可能需要使用其他方法。To find a row with a specific text, you'll want to use
.contains(selector, text)
to find the row then search within the row for the menu text to click.NOTE:
.contains()
will only return the first matching DOM element so if you have multiple matching names you may want to use a different approach.您也可以在和
parent
中使用:
You can also use
within
andparent
for this:基于您的
siblings()
解决方案,您可以在siblings()
命令中指定选择器Based on your
siblings()
solution, you can specify a selector inside thesiblings()
command