Warm tip: This article is reproduced from serverfault.com, please click

How to disable Javascript when using Selenium?

发布于 2009-08-17 02:17:04

I am wondering how do I disable javascript when using selenium so I can test server side validation.

I found this article but I don't know what to really do. Like I make this javascript file then what?

http://thom.org.uk/2006/03/12/disabling-javascript-from-selenium/

Questioner
chobo2
Viewed
0
mark 2018-08-24 13:23:32

Edit

In the meantime better alternatives did arise, please see the other answers e.g. https://stackoverflow.com/a/7492504/47573 .

Original answer

Other possibilities would be:

  • Write your application to support disabling JavaScript (yes, the web application).
    Sounds crazy? Isn't. In our development process we're doing exactly this, implementing features without JS until all are there, then spice up with JS. We usually provide a hook within all templates which can control from a single point to basically which JS off/on from the web application itself. And, yes, the application is hardly recognizable without JS enabled, but it's the best way to ensure things work properly. We even write Selenium tests for it, for both versions; NOJS and JS. The NOJS are so quickly implemented that they don't matter compared to what it takes to write sophisticated JS tests ...
  • Modify the appropriate browser profile to have JS disabled. I.e. for FF you can tell Selenium which profile to use; you can load this profile normally, disable JS in about:config and feed this profile as default profile to Selenium RC.