我想得到md-autocomplete的内部标记值,但我无法获得文本值,查找下面的代码

时间:2017-06-05 08:05:20

标签: javascript angularjs testing protractor angular-material

HTML:

<md-virtual-repeat-container role="presentation" ng-class="{ 'md-not-found': $mdAutocompleteCtrl.notFoundVisible() }" class="md-autocomplete-suggestions-container md-whiteframe-z1 md-virtual-repeat-container md-orient-vertical ng-hide" ng-hide="$mdAutocompleteCtrl.hidden" ng-mouseup="$mdAutocompleteCtrl.mouseUp()" ng-mouseleave="$mdAutocompleteCtrl.listLeave()" ng-mouseenter="$mdAutocompleteCtrl.listEnter()" md-auto-shrink-min="1" md-auto-shrink="" aria-hidden="true" style="left: 676.483px; min-width: 270.717px; max-width: 941.2px; top: auto; bottom: -147.917px; max-height: 240px; height: 96px;">
<div class="md-virtual-repeat-scroller">
    <div class="md-virtual-repeat-sizer" style="height: 96px;"></div>
    <div class="md-virtual-repeat-offsetter">
        <ul id="ul-3" ng-class="::menuClass" class="md-autocomplete-suggestions">
            <!-- mdVirtualRepeat: item in $mdAutocompleteCtrl.matches -->
            <li md-extra-name="$mdAutocompleteCtrl.itemName" ng-click="$mdAutocompleteCtrl.select($index)" ng-class="{ selected: $index === $mdAutocompleteCtrl.index }" md-virtual-repeat="item in $mdAutocompleteCtrl.matches" class="ng-scope" role="button" tabindex="0">
                <!-- mdAutocompleteParentScope: -->
                <md-autocomplete-parent-scope md-autocomplete-replace="" class="ng-scope">
                    <span md-highlight-text="searchText1" id="pincodeCity"><span class="highlight">110081</span>,Delhi</span>
                </md-autocomplete-parent-scope>
            </li>
            <li md-extra-name="$mdAutocompleteCtrl.itemName" ng-click="$mdAutocompleteCtrl.select($index)" ng-class="{ selected: $index === $mdAutocompleteCtrl.index }" md-virtual-repeat="item in $mdAutocompleteCtrl.matches" class="ng-scope" role="button" tabindex="0">
                <!-- mdAutocompleteParentScope: -->
                <md-autocomplete-parent-scope md-autocomplete-replace="" class="ng-scope">
                    <span md-highlight-text="searchText1" id="pincodeCity"><span class="highlight">110081</span>,Nizampur</span>
                </md-autocomplete-parent-scope>
            </li>
            <!-- ngIf: $mdAutocompleteCtrl.notFoundVisible() -->            
        </ul>
    </div>
</div>

量角器代码:

let foo = $$('.md-autocomplete-suggestions').$$('.highlight');
    expect(foo.getText()).toEqual([',Delhi', ',Nizampur']);

我尝试使用上面的代码,但它没有用。

我有什么方法可以在span标签中找到/选择文本字段。

2 个答案:

答案 0 :(得分:1)

好的,你必须把id放在跨度

ES:

 <span id="Spansearch" md-highlight-text="searchText1"><span class="highlight">110081</span>,Delhi</span>

在此之后,您可以使用此

获取所有HTML
$( "#Spansearch" ).html();

如果你不想只获得Nizampur

你可以用这个

$( "#Spansearch" ).html().split(",")[1];

答案 1 :(得分:1)

在量角器中,getText()返回您需要解决的承诺。所以当你使用expect时,你需要做那个你已经解决了这个承诺的帖子。

我想你可以做点什么

     let foo = $$('.md-autocomplete-suggestions').$$('.highlight>span[1]');
      foo.getText().then(function(text){
       expect(text).toEqual('Delhi');

       })