問題描述
我有一個錨標記列表,并且必須測試單擊列表中的第二個標記.
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();
這篇關于使用量角器在列表中選擇第二個錨元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!