gpt4 book ai didi

javascript - Protractor 获取下拉列表中所有项目的计数

转载 作者:行者123 更新时间:2023-11-30 19:39:14 26 4
gpt4 key购买 nike

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

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');

关于javascript - Protractor 获取下拉列表中所有项目的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com