开发者

Selenium assertText for all text in a table?

开发者 https://www.devze.com 2023-01-09 08:40 出处:网络
I n开发者_如何学Goeed 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:

I n开发者_如何学Goeed 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?


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]");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消