使用jQuery和Selenium IDE 1.0.8获取元素 [英] Get element with jquery and selenium IDE 1.0.8
问题描述
我正在尝试使用jquery和Selenium IDe 1.0.8来获取元素.
I'm trying to get element with jquery and Selenium IDe 1.0.8.
<td>storeValue</td>
<td>$('#result').find('img').filter('[alt="NameOfPhoto"]').eq(0)</td>
<td></td>
然后在日志中我得到
[error] Element $('#result').find('img').filter('[alt="NameOfPhoto"]').eq(0) not found
当我把这个命令放到萤火虫中时,我得到了这个元素:/
When I put this command in firebug I get this element :/
为什么不起作用?
另外,例如,您可以给我代码如何在stackoverflow主页上获取带有JAVA标签的第一个对象的ID.
Alternatively for example you can give me code how to get id of first object whith JAVA tag at main page of stackoverflow.
标签:
<a rel="tag" title="show questions tagged 'java'" class="post-tag" href="/questions/tagged/java">java</a>
以及示例结果:
<div id="question-summary-4303985" class="question-summary narrow">
是:
question-summary-4303985
推荐答案
基于其他帖子,我尝试了以下操作,并且有效.
Based on the other posts I tried the following and it worked.
将以下代码添加到user-extensions.js:
Add the code below to user-extensions.js:
function jQuery (selector)
{
return selenium.browserbot.getUserWindow().jQuery(selector);
}
然后您可以使用关键字jQuery而不是$来访问任何jQuery函数.只需确保您要测试的页面引用了jQuery js文件即可.
You can then access any jQuery function by using the keyword jQuery instead of the $. Just make sure that the page you are testing is referencing the jQuery js file.
这篇关于使用jQuery和Selenium IDE 1.0.8获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!