jquery - 使用 JQuery 选择器和 Selenium IDE 2.0.0 获取元素属性

标签 jquery selenium properties ide selector

我有一个网页,在页面加载后立即选择定制的 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/

相关文章:

javascript - JQuery AJAX 到 PHP 获取 undefined index

selenium - 使用 selenium : chrome screensharing auto select tab and share with audio 进行测试

iphone - 属性声明中的非原子和保留是什么意思

selenium - 如何将 Jsoup 与 WebDriver 集成?

javascript - 使用动态计算的名称访问对象属性

hadoop - 全面引用带有版本的sqoop.properties

javascript - 在 'click' 上重置 addClass 函数

jquery - 如何将子菜单添加到下拉菜单

javascript - 使用 jQuery 编码元素

python - Selenium /Python : How do I move to a new window with no window name given?