views:

39

answers:

1

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)");
A: 

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

Dave Hunt
I couldn't get that to work either. Thanks anyway. =]
Andrew
I've fixed my suggested workaround, I was missing the `tbody` element.
Dave Hunt