简体   繁体   English

量角器-是否可以将$$(elementLocator).first()用于更多元素,例如第二,第三等等。

[英]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.

相关问题 我如何比较Array.find和foreach等迭代器? - How can i compare Array.find with iterators like for foreach etc..? 如何获得第二行(第三行等)的缩进,以使用CSS使用自定义编号匹配列表中的第一行? - How can I get second (third, etc.) line indentation to match first line in a list with custom numbering using CSS? 如何将第三个网格的内容显示到第一个和第二个网格? - How can i show content of third grid to first and second grid? 我可以在 Xpath 的量角器搜索元素中使用循环概念吗? - Can I use Loop concepts in protractor searching elements by Xpath? 我如何调用HTML DOM事件对象(例如:onclick,onblur等)的嵌套函数? - How can I call to HTML DOM Event Object (for example: onclick, onblur, etc..) nested functions? 什么时候将在jQuery,mootools等库中构建JavaScript引擎(如Spidermonkey),并且有人可以帮助实现这一点? - When is a javascript engine (like Spidermonkey) going to build in a library like jquery, mootools, etc.. and how can anyone help this to come about? 获取列位置(如第一、第二等) - get column position (like first, second, etc.) 如何在 TextBox(用户、密码等)中缩进文本和光标的起始位置 - How can I indent the text, and starting position of cursor, in a TextBox (user, password, etc..) 想要在 3 个标签之后隐藏所有标签并与所有其他标签一起工作,就像我再使用一次 HTML 代码它与第一个和第二个一起工作 - Want to hide all tags after 3 tags and work with all other also like if i use one more time HTML code it work with first one and also with the second 量角器:如何拉伸和替换元素? - Protractor: How I can stretching and replasing elements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM