[英]Protractor - find element with “neighbour”
I'm currently creating a tests with protractor and phantomjs.我目前正在使用量角器和 phantomjs 创建一个测试。
What I'm trying to do is pretty simple, here is my html code containing the element I want to click.我想要做的很简单,这是我的 html 代码,其中包含我要单击的元素。
<tr class="moo" role="foo">
<td class="bar">
<input class="toto" value="42" type="checkbox"></input>
</td>
<td class="titi">
<a href="/path/to/something">Test</a>
</td>
</tr>
Here I need to click the checkbox element, quite easy actually with : element(by.xpath("//input[@type='checkbox']")).click();
在这里,我需要单击复选框元素,实际上很容易使用: element(by.xpath("//input[@type='checkbox']")).click();
But the problem is that there is many checkbox elements and the only difference between them is the "a" line with the text (Test in this example) that changes.但问题是有许多复选框元素,它们之间的唯一区别是“a”行与更改的文本(在此示例中为测试)。
My question is : how can I specify that.我的问题是:我该如何指定。 I want to click on the checkbox Where the text in "a" line is "Test" ?我想单击复选框“a”行中的文本是“Test”?
Use a CSS selector to find the row and then the cell:使用 CSS 选择器查找行,然后查找单元格:
element(by.cssContainingText('tr[role="foo"]', 'Test'))
.element(by.css('input'))
.click();
Or with an XPath to find the cell with a single call:或者使用 XPath 通过一次调用查找单元格:
element(by.xpath('//tr[td/a/text()="Test"]//input'))
.click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.