我有一个网页,在页面加载后立即选择定制的 Raphael 单选按钮。我正在尝试使用 Selenium IDE 2.0.0 和 FireFox 20.0.1 验证是否选择了适当的 id。
我尝试过以下方法...
|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('.response-options.selected').prop('id')} | |
...但结果我只是得到 null 。作为测试,我尝试过...
|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('#item-responses-A1_1a_No').prop('id')} | |
...但我仍然得到 null,即使我可以运行...
|assertElementPresent | #item-responses-A1_1a_No | |
...并通过。有趣的是,如果我跑...
|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('.response-options.selected')} | |
...(没有 .prop('id')),我得到一个“对象对象”。
有谁知道如何使用 JQuery 选择器获取元素属性?我已经看到发布的解决方案涉及 user-extensions.js 辅助函数,但看起来这实际上只是一个方便的函数,可以让您使用更少的文本来使用 JQuery 选择器。
谢谢!
最佳答案
assertEval 就是您要寻找的。不过,首先,您必须提前使用存储命令存储对 jquery 的引用。
这是一个例子:
<tr>
<td>store</td>
<td>this.browserbot.getUserWindow().jQuery</td>
<td>jq</td>
</tr>
<tr>
<td>assertEval</td>
<td>${jq}('.response-options.selected').prop('id')</td>
<td>**the name of the ID you want to match against**</td>
</tr>
关于jquery - 使用 JQuery 选择器和 Selenium IDE 2.0.0 获取元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16942163/