我想使用索引从下拉列表中选择一个值。我是量角器的初学者,并且在选择下拉菜单时陷入困境。这是几个下拉菜单的DOM,我已将量角器代码粘贴到DOM下方
<ng-dropdown-panel class="ng-dropdown-panel ng-select-bottom"
ng-reflect- klass="ng-dropdown-panel"
ng-reflect-items="[object Object],[object Object]"
ng-reflect-position="auto" ng-reflect-buffer-amount="4"
ng-reflect-virtual- scroll="false" id="a5a3c1993a27" style="opacity: 1;">
<div class="ng-dropdown-panel-items scroll-host">
<div></div>
<div>
<div class="ng-option" role="option" id="a93a68b7b452">
<span class="ng-option-label">Scholar1</span>
</div>
<div class="ng-option" role="option" id="aa1cf5337c38">
<span class="ng-option-label">Scholar2</span>
</div>
<div class="ng-option" role="option" id="a36388ede7a3">
<span class="ng-option-label">Scholar3</span>
</div>
</div>
</div>
</ng-dropdown-panel>
我尝试了以下量角器代码,测试未失败且未执行任何选择。在代码中,我给了索引2,以选择下拉列表中的第三个值。任何帮助将不胜感激。提前致谢。
exports.selectDropdownByNumber = function (element, index, milliseconds)
{
element.findElements(by.className('ng-dropdown-panel ng-select-bottom'))
.then(function (options) {
options[2].click();
});
if (typeof milliseconds != 'undefined') {
browser.sleep(5000);
}
};
谢谢 K
答案 0 :(得分:0)
您应该找到下拉选项:<div class="ng-option">
,而不是选项容器:<ng-dropdown-panel class="ng-dropdown-panel ng-select-bottom"
exports.selectDropdownByNumber = function (element, index, milliseconds)
{
element.findElements(by.css('ng-dropdown-panel.ng-select-bottom .ng-option'))
.then(function (options) {
options[2].click();
});
if (typeof milliseconds != 'undefined') {
browser.sleep(5000);
}
};