使用量角器选择列表中的第二个锚元素

Selecting second anchor element within lists using protractor

我有一个锚标签列表,必须测试点击列表中的第二个标签。

<ul id="shortcuts">
    <li><a ui-sref="app.journeyExplorer" href="#/journey-explorer/"><span class="ng-binding">1</span></a></li>
    <li><a ui-sref="app.userGroupManager" href="#/user-group-manager"><span class="ng-binding">2</span></a></li>
</ul>

经过大量调查和测试得出的结论是,正确的说法应该是:

element(By.id('shortcuts')).element(By.tagName('a')).get(1).click();

但是显示undefined。如果我使用 get() 它不起作用。没有得到它点击列表中的第一个锚标记并带有警告:'More than one anchor tag found, in such case the 1st one is selected'

有人可以帮忙解决这个问题吗?谢谢

您可能想尝试下面的选择器(注意 all() 而不是第二个 element() 来匹配所有锚点(这样接下来的 .get() 才有意义。

element(By.id('shortcuts')).all(By.tagName('a')).get(1).click();

或通过 .css

element(By.css('#shortcuts a:nth-child(1)').click();