开发者

Selenium RC: Selecting elements using the CSS :contains pseudo-class

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=#tabl开发者_开发百科e-1 tr:contains(Row 1 Col 1):contains(Row 1 Col 2)");


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜