如何用 Selenium 返回整列?

发布于 2024-08-31 05:01:03 字数 418 浏览 2 评论 0原文

我知道Selenium有一个内置方法 getTable("tableName.row.column") 可以方便地返回单元格。但是我怎样才能返回整列呢?

我直接尝试了 getText(),但是只返回了第一个单元格,

getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")

但是具有相同 Xpath 表达式的 getXpathCount() 显示有多个元素匹配。

getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]") // result is 15

请各位好心人帮忙,非常感谢!

I know that Selenium has a built-in method getTable("tableName.row.column") can return a cell conveniently. However how can I return a whole column?

I've tried getText() directly, however only the first cell was returned,

getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")

But getXpathCount() with the same Xpath expression showed there're multiple elements matched.

getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]") // result is 15

Please kindly help, many thanks!

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

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

发布评论

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

评论(1

南七夏 2024-09-07 05:01:03

您将需要迭代所有匹配的元素并将它们存储在某个地方。

所以

int matches = selenium.getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")
string[] column;
for (int i = 1; i < matches;i++){
  column.add(selenium.getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')][" + i + "]");

}

这将遍历包含您想要的所有匹配项的表,然后存储它们以供以后使用

You will need to iterate through all the elements that match and store them somewhere.

so

int matches = selenium.getXpathCount("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')]")
string[] column;
for (int i = 1; i < matches;i++){
  column.add(selenium.getText("//tbody[@id='recordsTable']/tr[contains(@class, 'someclass')][" + i + "]");

}

This will go through the table with all the matches you want and then store them for later use

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