首页 > 解决方案 > 如何从下拉数组中的元素数组中选择一个值

问题描述

我正在尝试从元素数组中选择一个下拉值(公司管理)。但是,以错误结束

失败:element.all(...).get(...).click(...).element.all 不是函数

谁能帮我解决这个问题。

量角器/JasmineJs 片段:

element.all(by.className('btn btn-default dropdown-toggle')).get(0).click().element
       .all(by.repeater('lookupData in lookupDataValues | filter: filteredValue'))
       .get(0).click();

代码片段:

    <button ng-disabled="customDisabled()" class="btn btn-default dropdown-toggle" type="button" style="min-width: 0px;padding: 3px;border-radius: 0px;"
    data-toggle="dropdown" ng-click="displayDropDownForSelectingValues()">
    <span style="background:white;border-right: white; font-size:12px;" id="statusinput" class="ng-binding"></span>
    <div class="caret_container" style="display:inline-block;">
        <span class="caret" style="margin-top: 0px;"></span>
    </div>
</button>
<ul class="dropdown-menu dropdown-menu-right dropdown-scroll" ng-click="preventBlur($event)" role="menu" ng-show="showList"
    style="">
    <li class="fa fa-cog fa-spin fa-3x fa-fw" ng-hide="hideLoading" style="margin-left: 50%; font-size: 18px; display: none;"></li>
    <li class="searchInputBox" ng-show="hideLoading &amp;&amp; showList" style="padding: 0px 2%;">
        <input type="text" ng-keyup="updateFilter()" id="managementTypeIdSearch" role="menuitem" class="searchInput" style="width:100%;">
        <span class="fa fa-search"></span>
    </li>
    <!-- ngRepeat: lookupData in lookupDataValues | filter: filteredValue -->
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Company Managed</a>
    </li>
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Customer Managed</a>
    </li>
</ul>

<button ng-disabled="customDisabled()" class="btn btn-default dropdown-toggle" type="button" style="min-width: 0px;padding: 3px;border-radius: 0px;"
    data-toggle="dropdown" ng-click="displayDropDownForSelectingValues()">
    <span style="background:white;border-right: white; font-size:12px;" id="statusinput" class="ng-binding"></span>
    <div class="caret_container" style="display:inline-block;">
        <span class="caret" style="margin-top: 0px;"></span>
    </div>
</button>
<ul class="dropdown-menu dropdown-menu-right dropdown-scroll" ng-click="preventBlur($event)" role="menu" ng-show="showList"
    style="">
    <li class="fa fa-cog fa-spin fa-3x fa-fw" ng-hide="hideLoading" style="margin-left: 50%; font-size: 18px; display: none;"></li>
    <li class="searchInputBox" ng-show="hideLoading &amp;&amp; showList" style="padding: 0px 2%;">
        <input type="text" ng-keyup="updateFilter()" id="resiliencyIdSearch" role="menuitem" class="searchInput" style="width:100%;">
        <span class="fa fa-search"></span>
    </li>
    <!-- ngRepeat: lookupData in lookupDataValues | filter: filteredValue -->
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">--Please Select--</a>
    </li>
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Backup</a>
    </li>
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Secure</a>
    </li>
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Secure+</a>
    </li>
    <li ng-repeat="lookupData in lookupDataValues | filter: filteredValue" class="ng-scope">
        <a ng-href="" role="menuitem" ng-click="updateValue(lookupData.key)" style="font-size:12px;" class="ng-binding">Standard</a>
    </li>
</ul>

错误:

Message:
  Failed: element.all(...).get(...).click(...).element.all is not a function
Stack:
  TypeError: element.all(...).get(...).click(...).element.all is not a function

标签: angularjsjasmineprotractor

解决方案


用分号 (;) 分隔两个element.all调用。

element.all(by.className('btn btn-default dropdown-toggle')).get(0).click();
element.all(by.repeater('lookupData in lookupDataValues | filter: filteredValue'))
       .get(0).click();

推荐阅读