Selenium RC:使用 CSS 选择元素:包含伪类

发布于 2024-09-05 02:04:22 字数 1325 浏览 2 评论 0原文

我想断言表行包含我在两个不同表中期望的数据。

使用以下 HTML 作为示例:

<table>
    <tr>
        <th>Table 1</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>Row 1 Col 2</td>
    </tr>
</table>

<table>
    <tr>
        <th>Table 2</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>different data</td>
    </tr>
</table>

以下断言通过:

$this->assertElementPresent('css=table:contains(Table 1)');

但是,这个断言没有通过:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1)');

最终,我需要能够测试表行中的两列是否包含我期望的数据:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1):contains(Row 1 Col 2)');
$this->assertElementPresent('css=table:contains(Table 2) tr:contains(Row 1 Col 1):contains(different data)');

我做错了什么?我怎样才能实现这个目标?

更新:

听起来这个问题是在尝试选择后代时 Selenium 中的一个错误。

我能够让它工作的唯一方法是在桌子上添加一个额外的标识符,这样我就可以知道我正在使用哪个标识符:

/* HTML */
<table id="table-1">

/* PHP */
$this->assertElementPresent("css=#table-1 tr:contains(Row 1 Col 1):contains(Row 1 Col 2)");

I would like to assert that a table row contains the data that I expect in two different tables.

Using the following HTML as an example:

<table>
    <tr>
        <th>Table 1</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>Row 1 Col 2</td>
    </tr>
</table>

<table>
    <tr>
        <th>Table 2</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>different data</td>
    </tr>
</table>

The following assertion passes:

$this->assertElementPresent('css=table:contains(Table 1)');

However, this one doesn't:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1)');

And ultimately, I need to be able to test that both columns within the table row contain the data that I expect:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1):contains(Row 1 Col 2)');
$this->assertElementPresent('css=table:contains(Table 2) tr:contains(Row 1 Col 1):contains(different data)');

What am I doing wrong? How can I achieve this?

Update:

Sounds like the problem is a bug in Selenium when trying to select descendants.

The only way I was able to get this to work was to add an extra identifier on the table so I could tell which one I was working with:

/* HTML */
<table id="table-1">

/* PHP */
$this->assertElementPresent("css=#table-1 tr:contains(Row 1 Col 1):contains(Row 1 Col 2)");

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

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

发布评论

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

评论(1

妞丶爷亲个 2024-09-12 02:04:23

这可能是由于 Selenium 使用的 CSS 选择器库中的错误所致。作为解决方法,您可能需要尝试以下方法:

css=table:contains(Table 1) > tbody tr:contains(Row 1 Col 1)

可以在此处找到错误的详细信息:http: //jira.openqa.org/browse/SEL-698

This is probably due to a bug in the CSS selector library used by Selenium. As a workaround you might want to try the following:

css=table:contains(Table 1) > tbody tr:contains(Row 1 Col 1)

Details of the bug can be found here: http://jira.openqa.org/browse/SEL-698

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