Retreiving the CheckBox value Using JQuery in Selenium

Like mentioned in the earlier post, retreving the checkbox values on a webpage can also be done using JQuery. Most of the blogs and tutorials we came across covered JQuery selectors, which involved a tedious process of repackaging the selenium-server.jar file. Since the browser recognizes JQuery, we just embedded the JQuery codes in our user-extensions.js, similar to wat was done in the previous post.

The JQuery code below gets the id of all check boxes on a webpage.

Selenium.prototype.getAllCheckBox = function() {   
var $n = this.browserbot.getCurrentWindow().jQuery.noConflict();
  var allVals = [];
        $n(‘input[type="checkbox"]‘).each(function() {
        return allVals;

As you can clearly recognize the second line of the code was slightly altered compared to the previous post, because JQuery didnt recognize on which browser it was running its scripts(i.e the test runner suite or the test browser). By declaring $ as a variable and specifying to which browser it actually denotes the checkbox values of the paricular webpage were retreived successfully.

The Selenium server has to be started with the -userExtensions option pointing to the user-extensions.js file. i.e as shown below(exactly the same way)

C:\selenium-rc\selenium-server-1.0.3>java -jar selenium-server.jar -userExtensions user-extensions.js

In the selenium code the above function can be called by using doCommand()

my $allRadios = $sel->do_command(“getAllCheckBox”, ”);

The same code can be used to identify the ids of buttons getAllButtons(), images, and dropdownlist too…..

One Response to “Retreiving the CheckBox value Using JQuery in Selenium”

  1. Joao says:

    Sorry for all the fuss.In FD3 FlashDevelop 3 (which is what I’m using and quite new to it and all of flash, as you can tell), I added the swc file to my src folder then from the prjoect tree within FD3 I right clicked on the swc file and selected add to library.In my case I copied the GFSClient.swc file to my src prjoect folder. Really didn’t matter where I copied it as you can see FD3 records that you’ve added it to the library. So regardless where this file sits, as long as you’ve added it to the library, as mentioned above, then it will be fine.When referencing a class in my as3 code all I have to do is go back to the prjoect tree, under libraries expand classes and double click on the click I wish to reference. It adds it for me in my AS3 code at the point where my cursor is located. I can then compile correctly.and the journey continues btw again Chad, great work, I’m incorporating your code for a game site i’m building and I’m very grateful for the hard work you’ve put into this.


Get every new post delivered to your Inbox

Join other followers