如何从下拉列表中的元素数组中选择一个值

时间:2018-06-01 07:47:15

标签: angularjs jasmine protractor

我正在尝试从元素数组中选择下拉值(公司管理)。但是,最终会出现错误

  

失败: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

1 个答案:

答案 0 :(得分:3)

用分号(;)分隔两个var btn = _driver.FindElement(By.XPath("//button[@data-purpose='add-section-btn']")); 次调用。

--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED