<div class="divName">
...
<a href="some url">some text</a>
<a href="some url">another text</a>
...
</div>
我可以使用 $('.divName a').click();
到达第一个 href,但是如何到达第二个 href?
最佳答案
通过在 element
上使用 .all
方法,您可以返回一个项目数组,然后您可以访问该数组。这避免了仅仅为了通过测试而添加类的需要。例如:
<div class="divName">
...
<a href="some url">some text</a>
<a href="some url">another text</a>
...
</div>
在 protractor 测试中:
var urls = element.all(by.css('.divName a'));
expect(urls.count()).toBe(2); //passes test
urls.get(1).click().then(function() { ... };
// access an item in array with the .get(index) method,
// then follow the link with click() should you wish
还有一个快捷方法:
var urls = $$('.divName a');
关于jquery - protractor : How to reach the second href?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759509/