I need to disable a particular JavaScript function of the main application for which I am creating automated tests using Selenium WebDriver.

Is there a way to do this?

1 Answer 1


Selenium is not designed to play in this way. Still on Selenium you can run your own JavaScript functions. In this case you can try override function which you want to disable (e.g. function functionWhichYouWantToBeDisabled(){return null;}). In this way it not be disabled but removed/changed functionality temporally. All what I say is more in theory level, I will not surprise if this won't work (I never try anything similar). Much easier way is completely disable JavaScript on browser. For example if you testing with Firefox you can create custom Firefox profile with disabled JavaScript.

  • 2
    You can execute JS with selenium, so this will work until original function source is re-loaded.
    – yoosiba
    Commented Jan 23, 2012 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.