I have a task to verify that the data in a table row matches my expectations for two different tables.
Let's look at an example using 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>
In this context, the following assertion passes successfully:
$this->assertElementPresent('css=table:contains(Table 1)');
However, this assertion does not pass as expected:
$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1)');
Ultimately, I aim to validate that both columns within the table row contain the anticipated data:
$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 could be causing these issues? How can I resolve them?
Update:
It seems like the issue could be related to a bug in Selenium when trying to select descendants.
To work around this problem, I had to add an extra identifier to the table so that it could be uniquely identified:
/* HTML */
<table id="table-1">
/* PHP */
$this->assertElementPresent("css=#table-1 tr:contains(Row 1 Col 1):contains(Row 1 Col 2)");