如何使用Protractor从带有ng-reflect-value的select中获取文本?

时间:2016-08-19 19:36:03

标签: javascript protractor

我有一个已经选中了值“雷”的下拉列表,我需要将此文本“雷”并插入变量,我该怎么办?

HTML

<dropdownlist _ngcontent-nnm-24="" id="tipoNorma" ng-reflect-itens="[object Object]" ng-reflect-id="tipoNorma" ng-reflect-selecionado="a4469d22-1188-467d-a78a-e385a2cc8eb9"><select class="form-control ng-valid ng-touched ng-dirty" ng-reflect-id="tipoNorma-select" id="tipoNorma-select" ng-reflect-disabled="false" ng-reflect-model="a4469d22-1188-467d-a78a-e385a2cc8eb9">
<option value="null">Selecione um tipo de norma...</option>
<option value="5980dfc1-ed08-4e5f-bdd7-144beb2fafe3" ng-reflect-value="5980dfc1-ed08-4e5f-bdd7-144beb2fafe3">Enunciado Orientativo</option>
<option value="e721782a-11ba-4828-ac3a-934f60652760" ng-reflect-value="e721782a-11ba-4828-ac3a-934f60652760">Instrução Normativa</option>
<option value="a4469d22-1188-467d-a78a-e385a2cc8eb9" ng-reflect-value="a4469d22-1188-467d-a78a-e385a2cc8eb9">Lei</option>
<option value="9d8ea2fd-efe9-410a-8062-f5607c56332d" ng-reflect-value="9d8ea2fd-efe9-410a-8062-f5607c56332d">Portaria</option>
<option value="8407a52d-a760-48a2-b780-ab93f5904565" ng-reflect-value="8407a52d-a760-48a2-b780-ab93f5904565">Provimento</option>
<option value="8b20cc7f-6be1-43a5-a0b7-ac2fe695b14c" ng-reflect-value="8b20cc7f-6be1-43a5-a0b7-ac2fe695b14c">Resolução</option>
<option value="8fe058a8-ece3-4ef5-8f74-17255a90066f" ng-reflect-value="8fe058a8-ece3-4ef5-8f74-17255a90066f">Súmula</option>
    </select>
    </dropdownlist>

1 个答案:

答案 0 :(得分:2)

您可以找到select元素并获取ng-reflect-model属性的值。然后,您可以在后续选择器中使用此值来查找option值:

$("#tipoNorma-select").getAttribute("ng-reflect-model").then(function (value) {
    $("option[ng-reflect-value='" + value + "']").getText().then(function (optionValue) {
        console.log(optionValue);
    });
});