使用JQuery选择器和Selenium IDE 2.0.0获取元素属性 [英] Get element property with JQuery selector and Selenium IDE 2.0.0

查看:283
本文介绍了使用JQuery选择器和Selenium IDE 2.0.0获取元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,可以在页面加载后立即选择一个自定义的Raphael单选按钮.我正在尝试验证是否使用Selenium IDE 2.0.0和FireFox 20.0.1选择了适当的ID.

I've got a webpage that selects a custom-made Raphael radio button immediately after the page loads. I'm trying to verify that the appropriate id is selected using Selenium IDE 2.0.0 and FireFox 20.0.1.

我尝试了以下方法...

I've tried the following...

|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('.response-options.selected').prop('id')} | |

...但是我得到的结果只是空值.作为测试,我已经尝试过...

...but I simply get null as a result. As a test, I've tried...

|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('#item-responses-A1_1a_No').prop('id')} | |

...但是即使我可以运行,我仍然会为空...

...but I still get null, even though I can run...

|assertElementPresent | #item-responses-A1_1a_No | |

...然后通过.有趣的是,如果我跑步...

...and pass. Interestingly, if I run...

|getEval | javascript{selenium.browserbot.getUserWindow().jQuery('.response-options.selected')} | |

...(没有.prop('id')),我得到一个对象对象".

...(without the .prop('id')), I get an "object Object".

有人知道如何使用JQuery选择器获取元素属性吗?我看到过发布的解决方案涉及到user-extensions.js帮助程序功能,但似乎确实是一个便捷功能,使您可以使用较少的文本来使用JQuery选择器.

Does anyone know how to get an element property with a JQuery selector? I've seen solutions posted that involve a user-extensions.js helper function, but it seems like that is really just a convenience function that lets you use JQuery selectors using less text.

谢谢!

推荐答案

assertEval是您想要的.不过,首先,您必须早些时候使用store命令存储对jquery的引用.

assertEval is what you're looking for. First though, you'll have to store a reference to the jquery using a store command earlier on.

这里是一个例子:

<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选择器和Selenium IDE 2.0.0获取元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆