How to Disable JavaScript While Using Selenium

Written by brian l. thompson
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Disable JavaScript While Using Selenium
Disabling JavaScript in Selenium tools requires the alteration of a file. (Jupiterimages/Photos.com/Getty Images)

Selenium refers to a suite of program tools (Selenium Core, IDE, and Remote Control) that are used to test Web applications. All of these tools work on both PC and Mac platforms and are compatible with a number of Web-browsing programs, programming languages and testing platforms. To disable JavaScript in Selenium, one should possess experience with Selenium and have basic knowledge of how to edit JavaScript by adding language to the user-extensions.js file.

Skill level:
Challenging

Other People Are Reading

Things you need

  • Selenium RC
  • Firefox
  • File zipping/unzipping program
  • Microsoft Notepad

Show MoreHide

Instructions

  1. 1

    Download the selenium-server.jar file and open it with a file unzipping program. Extract the user-extensions.js file, and place it in on your hard drive.

  2. 2

    Open the user-extenstions.js file with Microsoft Notepad. Add the following text commands to the file:

    Selenium.prototype.doDisableJavascript = function() {

    setJavascriptPref(false);
    

    };

    Selenium.prototype.doEnableJavascript = function() {

    setJavascriptPref(true);
    

    };

    function setJavascriptPref(bool) {

    prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
    
    prefs.setBoolPref("javascript.enabled", bool);
    

    }

  3. 3

    Check to see that the IDE program recognises the location of the modified user-extensions.js file. Add it to the selenium-server.jar file before zipping it again.

  4. 4

    Close the file zipping program. Execute Selenium RC by using the command line: Java -jar selenium-server.jar -user Extensions user-extensions.js.

    Activate the command to stop JavaScript by typing: "HttpCommandProcessor proc = new HttpCommandProcessor("myserver", 4444, "*chrome", "http://my/URL");

    DefaultSelenium sel = new DefaultSelenium(proc);

    ...

    sel.click("foo");

    ...

    proc.doCommand("typeRepeated", new String[] { "bar", "baz" });"

Tips and warnings

  • Selenium Core and RC are only supported by Internet Explorer 7 and 8, Safari 2 and 3, Firefox 2 and 3, and Opera 8 and 9. Selenium IDE is only supported by Firefox 2 and 3.
  • Any text editor can be used to open and edit a user-extensions.js file.
  • These instructions only work for Selenium RC.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.