Stefan Kendall
Stefan Kendall

Reputation: 67802

Selenium assertText for all text in a table?

I need to assert that each row in table contains a certain text string, either through selenium IDE or a Java test case. What's the best way to do this? Here's my current test:

Command    assertText
Target     //table[@id='myTable']//tbody//tr[not(@style)]/td[1]
Value      myValue

I need to test the first column of every row, but this only tests the first row. Is there an easy way to test every row?

Upvotes: 0

Views: 2301

Answers (1)

Kiersten Arnold
Kiersten Arnold

Reputation: 1894

I haven't used selenium IDE, only the java API, so here how I'd do it in java (or the basic idea at least)

int numRows = selenium.getXpathCount("table[@id='myTable']//tbody//" + 
        "tr[not(@style)]/td[1]").intValue();
String[] values = new String[numRows];
for (int i = 0; i < numRows; i++) {
    values[i] = selenium.getText("table[@id='myTable']//tbody//" +
            "tr[not(@style)][" + i + "]/td[1]");
}

Upvotes: 1

Related Questions