Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get element with jquery and 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=&quot;NameOfPhoto&quot;]').eq(0)</td>
<td></td>

And in log I get

[error] Element $('#result').find('img').filter('[alt="NameOfPhoto"]').eq(0) not found 

When I put this command in firebug I get this element :/

Why it doesn't work ?

EDIT: Alternatively for example you can give me code how to get id of first object whith JAVA tag at main page of stackoverflow.

TAG:

<a rel="tag" title="show questions tagged 'java'" class="post-tag" href="/questions/tagged/java">java</a>

and the example result from :

<div id="question-summary-4303985" class="question-summary narrow">

is:

question-summary-4303985
like image 458
user278618 Avatar asked Nov 15 '10 15:11

user278618


2 Answers

Based on the other posts I tried the following and it worked.

Add the code below to user-extensions.js:

function jQuery (selector)
{
    return selenium.browserbot.getUserWindow().jQuery(selector);
}

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.

like image 117
Johann Strydom Avatar answered Nov 16 '22 04:11

Johann Strydom


To use jQuery with Selenium IDE, it's location is below. (Be sure to have loaded jQuery in your page)

this.page().getCurrentWindow().wrappedJSObject.jQuery()

You can store the function location in a Selenium variable.

<tr>
    <td>store</td>
    <td>this.page().getCurrentWindow().wrappedJSObject.jQuery</td>
    <td>jq</td>
</tr>

Then you can use them in your Tests like:

<tr>
    <td>assertEval</td>
    <td>${jq}('div').attr('foo')</td>
    <td>bar</td>
</tr>

Above matches <div foo='bar' /> using jQuery.


Edit: Alternatively you could access it by:

this.browserbot.getUserWindow().jQuery
selenium.browserbot.getUserWindow().jQuery

source of alternate: http://cssgreut.wordpress.com/2010/12/20/run-selenium-ide-tests-with-jquery-selectors/

like image 21
Quang Van Avatar answered Nov 16 '22 04:11

Quang Van