Get element property with JQuery selector and Selenium IDE 2.0.0

拈花ヽ惹草 提交于 2019-12-08 04:57:32

问题


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')} | |

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

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.

Thanks!


回答1:


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.

Here is an example:

<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>



回答2:


Just in case it helps others, I wanted to just run javascript (including jquery statements in my page) and the accepted answer (1000s kudos to you Scottingham !) is the starting point. You just have to redefine $ sign with jQuery from getUserWindow !

Then add a runScript command, with in the target the following :

javascript{var $=this.browserbot.getUserWindow().jQuery; ... your javascript there}

For example

javascript{var $=this.browserbot.getUserWindow().jQuery; $('#myid').click();}

and remember that selenium only sees what is ctually visible on the page... and so do your jquery selectors in that context



来源:https://stackoverflow.com/questions/16942163/get-element-property-with-jquery-selector-and-selenium-ide-2-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!