1

I want to automate the webtable in angular. Here's the site- http://demo.automationtesting.in/WebTable.html

I want to capture all the records of all rows. Here what I tried-

List<WebElement> wbt=drv.findElements(By.cssSelector("div[role='rowgroup'][class='ui-grid-viewport ng-isolate-scope']"));
System.out.println("size"+wbt.size());

for(int i=0; i<wbt.size();i++){
    System.out.println("values-"+wbt.get(i).getText());
}

But the size coming out is 1.

I also tried with div[class='ui-grid-contents-wrapper'], but with no success.

Fábio Nascimento
  • 2,644
  • 1
  • 21
  • 27
bot13
  • 99
  • 1
  • 15

1 Answers1

1

You selector is pointing to the table div and to the rows. To get table rows you can use .ui-grid-row selector, that will give you table body rows.

List<WebElement> rows = drv.findElements(By.cssSelector(".ui-grid-row"));
for (WebElement row : rows) {
    System.out.println("values-" + row.getText());
}

To get each column element by row, you can use .ui-grid-cell-contents selector inside the loop:

List<WebElement> rows = drv.findElements(By.cssSelector(".ui-grid-row"));
for (WebElement row : rows) {
    columns = row.findElements(By.cssSelector(".ui-grid-cell-contents"));
    columns.forEach(column -> System.out.println(column.getText().trim()));
}

You can learn about selectors here.

Also you may need to wait until some conditions is met, information you can get from: When to use explicit wait vs implicit wait in Selenium Webdriver?

Sers
  • 12,047
  • 2
  • 12
  • 31
  • Thanks for the answer, but it seems getting class in angular webtable is difficult as in tr-td approach. On inspection I haven't seen that ui-grid-row class. Also will it work same as in tr-td , if i want to work on particular row or columns. – bot13 Apr 12 '19 at 10:33
  • Second code block in answer shows example how you can work on columns in row – Sers Apr 12 '19 at 10:35