Javascript 如何使用量角器在dropdowlist中随机获取元素?

Javascript 如何使用量角器在dropdowlist中随机获取元素?,javascript,angularjs,testing,protractor,Javascript,Angularjs,Testing,Protractor,我有一个下拉列表,我试图随机获得一个值并点击它。我怎么做?我无法使用该类,因为有其他元素具有相同的类。 我一点也不知道 <dropdownlist _ngcontent-lnd-30=""> <select class="form-control ng-pristine ng-valid ng-touched"> <!--template bindings={}--> <option value="null">Selecione u

我有一个下拉列表,我试图随机获得一个值并点击它。我怎么做?我无法使用该类,因为有其他元素具有相同的类。 我一点也不知道

<dropdownlist _ngcontent-lnd-30="">
<select class="form-control ng-pristine ng-valid ng-touched">
        <!--template bindings={}-->
<option value="null">Selecione um tipo de norma...</option>
<option value="5980dfc1-ed08-4e5f-bdd7-144beb2fafe3">Enunciado Orientativo</option>
<option value="e721782a-11ba-4828-ac3a-934f60652760">Instrução Normativa</option>
<option value="a4469d22-1188-467d-a78a-e385a2cc8eb9">Lei</option>
<option value="9d8ea2fd-efe9-410a-8062-f5607c56332d">Portaria</option>
<option value="8407a52d-a760-48a2-b780-ab93f5904565">Provimento</option>
<option value="8b20cc7f-6be1-43a5-a0b7-ac2fe695b14c">Resolução</option>
<option value="8fe058a8-ece3-4ef5-8f74-17255a90066f">Súmula</option>
 </select></dropdownlist>

千里光。。。
方向性发音
规范研究所
雷
门静脉
普罗维门托
Resolução
苏穆拉

您可以像这样选择选项数组的随机索引

// get your options first
// var options = angular.element(...) or getElementByID(...) Whatever your flavor.
var selectRandomOption = options[Math.floor(Math.random() * options.length)]

计算选项的数量(它是异步的,因此您将链接一些承诺),然后获取1和总计数之间的随机数,然后获取特定元素并单击它

var allOptions = element(by.tagName('dropdownlist')).all(by.tagName('option'));

allOptions.count().then(function(numberOfItems) {
    return Math.floor(Math.random() * numberOfItems) + 1;
}).then(function(randomNumber) {
    allOptions.get(randomNumber).click();
});

它工作得很好。如果我有多个带有标记名dropdownlist的元素,我应该怎么做?使用适当的选择器查找该元素:
element(by.css('tagName[\ngcontent-lnd-30=”“])