Rajkamal S.
Rajkamal S.

Reputation: 35

How to get the value and size of dynamic table's columns and rows

I have used Karate for API testing and succeeded with one project. And now I am exploring the Karate UI for an another project and I am stuck with getting values from the dynamic table's column and rows and also I want to check its size.

I have gone through the documentation and found some way to handle it like using locateAll and scriptAll but it didn't help.

My table looks like below

<table>
 <thead>
  <tr>
   <th>column1</th>
   <th>column2</th>
  </tr>
 </thead>
 <tbody>
  <tr>row1</tr>
  <tr>row2</tr>
 </tbody>
</table>

I have achieved this in selenium by the below code

@FindBy(xpath = "//*[@id=\"PartialRateTableListModel\"]/div/div/div[2]/div/div[2]/table/thead/tr")
    private static WebElement columns;

    @FindBy(xpath = "//*[@id=\"PartialRateTableListModel\"]/div/div/div[2]/div/div[2]/table/tbody")
    private static WebElement rows;

List<WebElement> TotalColsList = columns.findElements(By.tagName("th"));
Assert.assertEquals(2, TotalColsList.size());

    List<WebElement>TotalRowsList = rows.findElements(By.tagName("tr"));
    Assert.assertEquals(2, TotalRowsList.size());

I want to this in our Karate UI. Can you please help me to overcome this. Thanks in advance

Upvotes: 1

Views: 1038

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

Here you go:

* def cols = scriptAll('th', "_.innerHTML")
* match cols == ['column1', 'column2']

Upvotes: 1

Related Questions