如何使用 Selenium RC 检索表列中的文本?

发布于 2024-08-23 22:40:55 字数 798 浏览 2 评论 0原文

我有一个如下所示的表:

<table class="theClass">
<tr>
   <td class="anotherClass"><strong>Label1:</strong></td>
   <td colspan="3">Value1a<br/>Value1b<br/>Value1c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label2:</strong></td>
   <td colspan="3">Value2a<br/>Value2b<br/>Value2c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label3:</strong></td>
   <td colspan="3">Value3a<br/>Value3b<br/>Value3c</td>
</tr>
</table>

How can I use Selenium RC to检索 Value1a、Value1b 和 Value1c ?我可以使用 selenium.getText(...) 或 storeText(...) 吗?如果是这样,我应该使用什么正确的 xpath?请假设该表无法更改。谢谢!

I have a table that looks like the following:

<table class="theClass">
<tr>
   <td class="anotherClass"><strong>Label1:</strong></td>
   <td colspan="3">Value1a<br/>Value1b<br/>Value1c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label2:</strong></td>
   <td colspan="3">Value2a<br/>Value2b<br/>Value2c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label3:</strong></td>
   <td colspan="3">Value3a<br/>Value3b<br/>Value3c</td>
</tr>
</table>

How can I use Selenium RC to retrieve Value1a, Value1b, and Value1c ? Can I use selenium.getText(...) or storeText(...)? If so, what is the proper xpath I should use? Please assume that the table cannot be changed. Thanks!

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

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

发布评论

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

评论(4

淡淡の花香 2024-08-30 22:40:55

会是

string value1 = selenium.getTable("table.1.2");
string value2 = selenium.getTable("table.2.2");

这样。

getTable 的帮助文本是

getTable(tableCellAddress) 参数:

  • tableCellAddress - 单元格
    地址,例如“foo.1.4”

    返回:
    指定单元格中的文本

    从表格的单元格中获取文本。单元格地址语法
    tableLocator.row.column,其中 row 和
    列从 0 开始。

it would be

string value1 = selenium.getTable("table.1.2");
string value2 = selenium.getTable("table.2.2");

and so on.

The help text for getTable is

getTable(tableCellAddress) Arguments:

  • tableCellAddress - a cell
    address, e.g. "foo.1.4"

    Returns:
    the text from the specified cell

    Gets the text from a cell of a table. The cellAddress syntax
    tableLocator.row.column, where row and
    column start at 0.

↙温凉少女 2024-08-30 22:40:55

检查这一点,

            int i =1;

       while(selenium.isElementPresent("//table/tbody/tr["+i+"]/td[2]")){
           System.out.println(selenium.getText("//table/tbody/tr["+i+"]/td[2]"));
           i++;
       }

结果将包含列出的所有值。希望它有帮助!

Check this,

            int i =1;

       while(selenium.isElementPresent("//table/tbody/tr["+i+"]/td[2]")){
           System.out.println(selenium.getText("//table/tbody/tr["+i+"]/td[2]"));
           i++;
       }

Result will contain all the values listed.Hope it helps!!!

谜兔 2024-08-30 22:40:55
String value1 = selenium.getText("//tr[1]/td[1]/strong[contains(text(), Label1:')]/../../td[2]");
String value1 = selenium.getText("//tr[1]/td[1]/strong[contains(text(), Label1:')]/../../td[2]");
九歌凝 2024-08-30 22:40:55

硒.gettable(xpath)

selenium.gettable(xpath)

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