Selenium assertText 用于表中的所有文本?

发布于 2024-09-12 07:47:14 字数 254 浏览 6 评论 0原文

我需要通过 selenium IDE 或 Java 测试用例断言表中的每一行都包含特定的文本字符串。最好的方法是什么?这是我当前的测试:

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

我需要测试每一行的第一列,但这仅测试第一行。有没有一种简单的方法来测试每一行?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2024-09-19 07:47:14

我没有使用selenium IDE,只使用过java API,所以这里是我如何在java中做到这一点(或者至少是基本想法)

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

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]");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文