Subburaj
Subburaj

Reputation: 2334

How to get the list item values from the table data in Selenium WebDriver?

I am having one webtable with class name as MessageTable and having the below list item inside the table data(td)

<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>

I need to read all the above content (Validation1,Validation2,Validation3) from web page and need to validate against the expected validation Message.

Upvotes: 0

Views: 2913

Answers (2)

Subburaj
Subburaj

Reputation: 2334

I have found the solution for the above question. Please find the working steps

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

        for(WebElement element:rows ){

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

    }

Upvotes: 0

noor
noor

Reputation: 3004

I assume that class="ng-binding ng-scope" ng-repeat="error in errors" only appears in your table.
Try this:

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.
    }
}

Upvotes: 1

Related Questions