views:

25

answers:

1

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?

+1  A: 

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]");
}
carnold
This also illustrates my other issue: how to select xpath elements by index AND attribute. :P
Stefan Kendall