[英]Protractor - Can I use $$(elementLocator).first() for more elements like the second, third and etc..?
Can I use $$(elementLocator).first()
for more elements like the second, third and etc..? 我可以将
$$(elementLocator).first()
用于更多元素,例如第二,第三等吗?
or is it just for the first and the last elements? 还是只针对第一个和最后一个元素?
For example - I've a drop down list with 5 buttons inside but they have the some properties and I want to click on all of them one by one.. so the first one will be: 例如-我有一个带有5个按钮的下拉列表,但是它们具有一些属性,我想一个一个地单击它们。.因此,第一个将是:
$$("button.font-sm.md-button.md-ink-ripple").first().click();
And how can I click on the second option? 我该如何点击第二个选项?
This is the element properties: 这是元素属性:
<button class="font-sm md-button md-ink-ripple" type="button" ng-transclude="" ng-click="actionClick(saction, $event)"><span class="ng-binding ng-scope">Message</span></button>
I know that it possible to use the Xpath, but i prefer some a stable locator. 我知道可以使用Xpath,但我更喜欢一些稳定的定位器。
You can use get()
function that's built in protractor. 您可以使用量角器内置的
get()
函数。 get()
function is a zero index based function. get()
函数是基于零索引的函数。 Here's how to use it - 这是使用方法-
$$("button.font-sm.md-button.md-ink-ripple").get(0).click(); //Click first element
$$("button.font-sm.md-button.md-ink-ripple").get(1).click(); //Click second element
You can always use first()
and last()
functions that are implementations of get()
function internally. 您始终可以在内部使用作为
get()
函数实现的first()
和last()
函数。 Hope it helps. 希望能帮助到你。
You can use .get(x), where x is the zero-based index of an item. 您可以使用.get(x),其中x是项目的从零开始的索引。
$$("button.font-sm.md-button.md-ink-ripple").get(1).click(); //Click second item
$$("button.font-sm.md-button.md-ink-ripple").last().click(); //Click last item
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.