How to use JQuery in Selenium?

Viewed 54992

I would like to use Selenium to click on the tab of a web where the tab was created dynamically using JQuery. There is one problem, since it was created dynamically and the tab got no ID tied to it (only class-ID provided), so I am running out of clue to click on it using Selenium.

After googling for 2 weeks, I found out that it could be done using JQuery by injecting JQuery into Selenium and repackaging it so that it support JQuery API. But the problem now is I don't know how to trigger JQuery script in Selenium?

Is there any resources out there or guideline on setting up JQuery in Selenium? How am I going to execute JQuery in Selenium?

6 Answers

You could use window.jQuery in getEval command:

|getEval | window.jQuery('div#main button').click(); | |

It works for me on Selenium IDE.

For FF3, use wrappedJSObject to get jQuery object:

|getEval | win = (this.page().getCurrentWindow().wrappedJSObject) ? this.page().getCurrentWindow().wrappedJSObject : this.page().getCurrentWindow() | |
|getEval | jq = win.jQuery | |
|assertEval | jq("div#main button").text() | click me! |
Related