第二,第三,第四,…使用CSS定位器定位量角器中的第八个元素
Locating second, third, fourth,...eigth element in protractor using css locator
我一直在使用量角器进行测试,除了通过css之外没有办法引用元素,因为它只具有给定的类属性。问题是有超过7个元素具有这个类名。因此我使用语法
element.all(by.css('h4.ng-binding')).first();
对于第一个,它工作得很好,但对于其他的不起作用!我用了和第一个一样的逻辑。以下是我的代码片段,以便其他人找到它们。
element.all(by.css('h4.ng-binding')).second();
element.all(by.css('h4.ng-binding')).third();
element.all(by.css('h4.ng-binding')).fourth();
element.all(by.css('h4.ng-binding')).fifth();
element.all(by.css('h4.ng-binding')).sixth();
element.all(by.css('h4.ng-binding')).seventh();
element.all(by.css('h4.ng-binding')).eighth();
量角器没有这些功能。只有first()
、last()
、get()
功能可用。您可以在ElementArrayFinder
之上使用这3个函数实现所有内容。-
element.all(by.css('h4.ng-binding')).first(); //get the first element
element.all(by.css('h4.ng-binding')).get(0); //get the first element as get() function is a '0' based index
element.all(by.css('h4.ng-binding')).get(1); //get the second element
element.all(by.css('h4.ng-binding')).get(2); //get the third element
element.all(by.css('h4.ng-binding')).last(); //get the last element
希望能有所帮助。
现在您可以使用.second(); .third(); .fourth();
等函数-我开发了一个小包- https://github.com/Marketionist/protractor-numerator -可以与量角器一起使用,以选择第二,第三,第四等元素
使用n -child即
element.all(by.css('h4.ng-binding:nth-child(2)'))...
相关文章:
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- jquery IE7中的第n个选择器
- 什么'这是从第三个函数上的async 1st函数获得结果的更好方法
- javascript第三个XMLHttpRequest被拒绝.但前两个是允许的
- 将循环中的两个文本框相乘,并在第三个文本框上显示结果
- 根据前两个下拉ID显示第三个下拉列表
- 是否可以在第n个元素处重复启动ng
- 使用jQuery获取第N个元素的数据属性值
- regex来构建字符串,直到遇到第N个匹配项
- 保存两个模型(属于第三个模型)和一个提交
- 每第n个图像具有下一个循环的余数偏移
- 如何在JavaScript中每隔第n个字符分割一个字符串
- Javascript 样式的第 n 个孩子
- 找到第 n 个 Prime JavaScript
- 如何根据 js 中每个单词的第 n 个字母按字母顺序排列列表
- Javascript 删除特定的只需要数组的第 n 个元素
- 使用第 n 个类型设置一组八个元素的样式
- CSS:在 for 循环中使用第 n 个子项
- 如何在javascript中将类添加到第三个
- 元素
- 第二,第三,第四,…使用CSS定位器定位量角器中的第八个元素