繁体   English   中英

量角器获取下拉列表中所有项目的计数

[英]Protractor Get count of all items in a drop list

我正在尝试获取下拉列表中所有选项的数量。 下面是我认为应该工作的代码,但它没有

let elements_count  = await $$('#directClassBased > option').count();
console.log('\nThe length of the elements are'+ await elements_count+' \n');

代码返回计数为 0。如何修复?

dropbox相关的html如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><select _ngcontent-c16="" class="form-control ng-dirty ng-valid ng-touched" formcontrolname="dcbsId" id="directClassBased">
        <!---->
        <option _ngcontent-c16="" value="0: C92AB645-9485-4A15-8F49-5412D1639962">Addison</option>
        <option _ngcontent-c16="" value="1: A85A556D-ABCA-44E5-80A5-9AF313E161FC">Dundalk</option>
        ....
        ....
    </select></title>
</head>
<body>

</body>
</html>

试试下面的方法

const elements_count  = element.all(by.css('#directClassBased > option'));
const drop = element(by.css('#directClassBased'));

await drop.click(); // to open the drop down 
await browser.sleep(1000);
console.log('\nThe length of the elements are'+ await elements_count.count() +' \n');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM