Selenium RC:使用 CSS 选择元素:包含伪类
我想断言表行包含我在两个不同表中期望的数据。
使用以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于 Selenium 使用的 CSS 选择器库中的错误所致。作为解决方法,您可能需要尝试以下方法:
可以在此处找到错误的详细信息: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:
Details of the bug can be found here: http://jira.openqa.org/browse/SEL-698