2016-04-29 61 views
0

は私が(TD)私はウェブから上記のすべてのコンテンツ(Validation1、Validation2、Validation3)を読む必要がselenium webdriverのテーブルデータからリスト項目の値を取得する方法は?

<td> 
<ul class="error"> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation1</li> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation2</li> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation3</li> 
</ul> 
</td> 

MessageTableとしてクラス名を持つ1 webtableを有するテーブルデータ内の下のリスト項目を過ごしています考えてみましょう期待される検証メッセージに対して検証する必要があります。

このシナリオを解決するのに手伝ってください。

+0

コレクション「リスト」コレクションを作成してスピンしてみませんか?どの言語で – Brian

+0

? –

+0

ブライアンに感謝します。私はList コレクションを使用していますが、私のシナリオではうまくいきます。WebElement table = driver.findElement(By.className( "messageTable")); リスト rows = table.findElements(By.tagName( "li")); (WebElementエレメント:行)のため \t \t \t \t \t \t \t \t {\t \t \t \t \t \t \tのSystem.out.println(element.getText())。 \t \t} – Subburaj

答えて

1

class="ng-binding ng-scope" ng-repeat="error in errors"はあなたのテーブルにのみ表示されるとします。私は上記の質問のためのソリューションを発見した

List<WebElement> elems= driver.findElements(By.cssSelector("li.ng-binding.ng-scope[ng-repeat$='errors']")); 

for(WebElement element:elems){ 
    if(element.getText().equals("ur validation message")){ 
     //do something as ur wish. 
    } 
} 
+0

ありがとうございました。私は以下の手順を使用しており、正常に動作しています。 for(WebElement要素:行){System.out.println(element.getText()); } – Subburaj

0


はこれを試してみてください。作業手順を見つけてください

WebElement table = driver.findElement(By.className("messageTable")); 
    List<WebElement> rows = table.findElements(By.tagName("li")); 

     for(WebElement element:rows){ 

      System.out.println(element.getText()); 

    } 
関連する問題