使用量角器选择列表中的第二个锚元素 [英] Selecting second anchor element within lists using protractor

查看:96
本文介绍了使用量角器选择列表中的第二个锚元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of anchor tags and have to test clicking the 2nd tag in the list.

<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>

经过大量调查和测试后得出的正确陈述应该是:

After much investigation and testing reached at the conclusion that the correct statement should be:

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

但它显示未定义。如果我使用get()它不起作用。没有得到它点击列表中的第一个锚标记并带有警告:'找到多个锚标记,在这种情况下,第一个被选中'

But it shows undefined. If I use get() it doesn't work. without get it clicks the 1st anchor tag in the list with a warning: 'More than one anchor tag found, in such case the 1st one is selected'

有人可以请帮帮忙吗?谢谢。

Can someone please help out with this ? Thanks.

推荐答案

您可能想尝试下面的选择器(注意 all()而不是第二个元素()来匹配所有锚点(以便接下来的 .get()感觉。

You might want to try selector below (note all() instead of second element() to match all anchors (so that .get() that comes next makes any sense.

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

或通过.css

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

这篇关于使用量角器选择列表中的第二个锚元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆