2017-11-18 11 views
0


私は、テーブルを反復する方法をさまざまな例で検討してきました。分度器はtdクラス内の特定の値を見つける

私がセレンのために以下のコードを使用している場合、私は欲しいものを正確に取得します。

driver.findElement(By.xpath("//td[contains(.,'Apple Pomace')]")); 

私の代わりに、コードを反復処理し、以下の値を見つけるためにしたいと思いますけれども:2ヶ所

See image

でアップル搾りかすがある

<td class="ng-binding">Apple Pomace</td> 

お知らせテーブルがあります:

<div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1"> 
    <h3 ng-show="searchQuery" class="page-header page-header-sm"><span translate="TITLE_SEARCH_RESULTS" class="ng-scope">Search Results</span> <span class="label label-default ng-binding" ng-bind-html="searchQuery">Apple Pomace</span></h3> 
    <h3 ng-show="!searchQuery" class="page-header page-header-sm ng-scope ng-hide" translate="TITLE_ALL_PRODUCTS">All Products</h3> 

    <div class="alert-info ng-hide" ng-show="confirmation"> 
     <p class="ng-binding"></p> 
    </div> 

    <table class="table table-striped table-bordered table-condensed"> 
     <tbody><tr> 
      <th translate="LABEL_IMAGE" class="ng-scope">Image</th> 
      <th translate="LABEL_PRODUCT" class="ng-scope">Product</th> 
      <th translate="LABEL_DESCRIPTION" class="ng-scope">Description</th> 
      <th translate="LABEL_PRICE" class="ng-scope">Price</th> 
      <th></th> 
     </tr> 
     <!-- ngRepeat: product in products --><tr data-ng-repeat="product in products" class="ng-scope" style=""> 
      <td><img src="/public/images/products/apple_pressings.jpg" class="img-responsive img-thumbnail" style="width: 200px" ng-click="showDetail(product.id)"></td> 
      <td class="ng-binding">Apple Pomace</td> //here is the item I want to fetch 'Apple Pomace' 
      <td><div ng-bind-html="product.description" class="ng-binding">Finest pressings of apples. Allergy disclaimer: Might contain traces of worms. Can be <a href="/#reccyle">sent back to us</a> for recycling.</div></td> 
      <td class="ng-binding">0.89</td> 
      <td> 
       <div class="btn-group"> 
        <a class="btn btn-default btn-xs" ng-click="showDetail(product.id)"><i class="fa fa-eye"></i></a> 
        <a class="btn btn-default btn-xs ng-hide" ng-click="addToBasket(product.id)" ng-show="isLoggedIn()"><i class="fa fa-cart-plus"></i></a> 
       </div> 
      </td> 
     </tr><!-- end ngRepeat: product in products --> 
    </tbody></table> 

</div> 

私は次のコードを作成しましたが、私の意見では正しくありません。その重要なのは、TD-クラスの結合ngの "を反復処理する理由です

element.all(by.css('.ng-binding')).each(function(element, index) 
      { 
      element.getText().then(function (text) 
      { 


      }); 
      }) 

予告私は2つの場所に「Appleの搾りかす」を得ました。あなたがフィルタリングしたい場合場合

element(by.cssContainingText('.table td', 'Apple Pomace')) 

誰かがあなたがちょうどあなたがこれを使用することができTDにアクセスしたい場合は

が場合は、事前

答えて

0

にありがとう、私を助けてもらえ製品のテーブル内の行とコードスニペットの下で使用できる要素を取得します。

element.all(by.repeater('product in products')).filter(function(elem, index) { 
    return elem.element(by.cssContainingText('td', 'Apple Pomace')).isPresent(); 
}).first(); 
+0

彼は要素を得る最後のコードスニペットは関数ではありません。 –

+0

これは、 'element.all()'に対して 'by.repeater()'が行われているため、 'element.allで始まり​​ます(by.repeater(...')で動作します) –

+0

コード。..今すぐお試しください – Rakesh

関連する問題