Selecting second anchor element within lists using protractor(使用量角器在列表中选择第二个锚元素)
问题描述
我有一个锚标记列表,并且必须测试单击列表中的第二个标记.
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() 而不是第二个 element()匹配所有锚点(以便接下来出现的 .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();
这篇关于使用量角器在列表中选择第二个锚元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用量角器在列表中选择第二个锚元素
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
