量角器无法计算列表中的链接 (li)
Protractor not able to count links in a list (li)
这是我的第一条消息,主要是因为这是我第一次找不到问题的答案。
我正在尝试计算下拉列表中 li 元素的数量。每个 <li> has a
` link。这是 HTML 代码:
<div ko-dropdown="ko-dropdown" ng-keyup="onKeyup($event)" ng-keydown="onKeydown($event)" class="dropdown ng-isolate-scope" ta-items="languages" ta-value="language" ta-onselect="select(lang)">
<div ng-click="toggle()" ng-class="{'is-open': open}" class="dropdown__toggle dropdown__toggle--top">English</div>
<ul ko-drop-menu="ko-drop-menu" ng-mouseleave="onMouseLeave($event)" class="dropdown__menu">
<!-- ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope is-active"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="en">English</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="fi">Suomi</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="sv">Svenska</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="no">Norsk</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="de">Deutsch</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
</ul>
</div>
量角器应该 return 的正确元素数量是 5,但在寻找元素数量时,我总是得到 10。
我正在使用这段代码进行调用,但如前所述,即使结合 dropdown__link,我总是得到 10,等等:
`elements.all(by.css('.dropdown__menu .dropdown__item')).count()`
使您的选择器更具体:
div[ta-items=languages] ul.dropdown__menu > li.dropdown__item
或者,通过链接 element
和 element.all
以及 by.repeater
:
var languageMenu = element(by.css("div[ta-items=languages]"));
var languages = languageMenu.all(by.repeater("item in items"));
expect(languages.count()).toEqual(5);
arr=browser.driver.findElement(by.tagName("a"));
for(var x = 0; x < arr.count; x++)
{
console.log('vishnu');
console.log(arr[i]);
}
这是我的第一条消息,主要是因为这是我第一次找不到问题的答案。
我正在尝试计算下拉列表中 li 元素的数量。每个 <li> has a
` link。这是 HTML 代码:
<div ko-dropdown="ko-dropdown" ng-keyup="onKeyup($event)" ng-keydown="onKeydown($event)" class="dropdown ng-isolate-scope" ta-items="languages" ta-value="language" ta-onselect="select(lang)">
<div ng-click="toggle()" ng-class="{'is-open': open}" class="dropdown__toggle dropdown__toggle--top">English</div>
<ul ko-drop-menu="ko-drop-menu" ng-mouseleave="onMouseLeave($event)" class="dropdown__menu">
<!-- ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope is-active"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="en">English</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="fi">Suomi</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="sv">Svenska</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="no">Norsk</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
<li ko-drop-item="ko-drop-item" ng-repeat="item in items track by $index" ng-mouseenter="onMouseEnter($event, item)" ng-click="select($event, item)" ng-class="{'is-active': item.selected}" class="dropdown__item ng-scope"><a class="dropdown__link ng-binding ng-scope" href="" ng-bind="::item[label]" data-value="de">Deutsch</a>
</li>
<!-- end ngRepeat: item in items track by $index -->
</ul>
</div>
量角器应该 return 的正确元素数量是 5,但在寻找元素数量时,我总是得到 10。
我正在使用这段代码进行调用,但如前所述,即使结合 dropdown__link,我总是得到 10,等等:
`elements.all(by.css('.dropdown__menu .dropdown__item')).count()`
使您的选择器更具体:
div[ta-items=languages] ul.dropdown__menu > li.dropdown__item
或者,通过链接 element
和 element.all
以及 by.repeater
:
var languageMenu = element(by.css("div[ta-items=languages]"));
var languages = languageMenu.all(by.repeater("item in items"));
expect(languages.count()).toEqual(5);
arr=browser.driver.findElement(by.tagName("a"));
for(var x = 0; x < arr.count; x++)
{
console.log('vishnu');
console.log(arr[i]);
}