0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I've fixed my suggested workaround, I was missing the tbody element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.