2016-11-22 92 views
2

在我的測試中,我需要先找到一個特定的產品,然後對該產品的某些子元素進行一些操作。有很多產品。量角器:找不到元素的元素

這是我的第一個量角器劇本,所以忍受着我。

var prod = element.all(by.css('singleproduct')).get(1); 

singleproduct是一個指令。 這是它打破了腳本的一部分:

prod.element(by.css(".product-ordering ul li")).each(function(elem) { 

}) 

不過,我總是得到element(...).each is not a function

HTML:

<singleproduct ng-repeat="item in vm.products" item="::item" class="col-xs-12 col-sm-6 col-md-4 product_tile ng-scope ng-isolate-scope"> 
    <article ng-class="{'product--active': isSelected}" class="product"> 
     <section ng-click="toggleDetails()" class="product-content"> 
     <!-- some prod info --> 
     </section> 
     <section>    
     <div class="product-ordering"> 
      <ul class="product-quantities"> 
       <!-- ngRepeat: option in ::priceList --> 
       <li ng-repeat="option in ::priceList" class="ng-scope"> 
        <!-- this is the LI I want to catch... 
       </li> 
       <!-- end ngRepeat: option in ::priceList --> 
       <li ng-repeat="option in ::priceList" class="ng-scope"> 
        <!-- this is the LI I want to catch... 

       </li> 
       <!-- end ngRepeat: option in ::priceList --> 
       <li ng-repeat="option in ::priceList" class="ng-scope"> 
        <!-- this is the LI I want to catch... 
       </li> 
       <!-- end ngRepeat: option in ::priceList --> 
      </ul> 
     </div> 
     </section> 
    </article> 
</singleproduct> 
+2

你已經有了不錯的問題,它的啓發可以添加對新eslint規則,請GitHub的問題,如果有興趣:https://github.com/alecxe/eslint-plugin-protractor/issues/57 。謝謝。 – alecxe

+0

@alecxe我不知道你的插件存在,看起來很有用! – faboolous

+0

我是個白癡,我意識到我實施了這個規則:請參閱https://github.com/alecxe/eslint-plugin-protractor/blob/master/docs/rules/no-array-finder-methods .MD。謝謝。 – alecxe

回答

3

each()功能將只用數組。但prod.element(by.css(".product-ordering ul li"))將返回給您一個ElementFinder而不是ElementArrayFinder。您需要使用product.all()而不是product.element()。看下面的例子。

prod.all(by.css(".product-ordering ul li")).each(function(elem) { 

}) 
+0

我只是想回答我自己的問題,因爲我也發現了。謝謝! – faboolous