Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Javascript when using Selenium?

Tags:

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/

like image 333
chobo2 Avatar asked Aug 17 '09 02:08

chobo2


People also ask

How do I shut off JavaScript?

Press Ctrl + Shift + P (Windows, Linux) or Command + Shift + P (macOS) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.

How do I disable JavaScript in my browser settings?

Go to the menu Tools "> Internet Options "> Security "> Custom Level. Scroll to the Scripting section and click disable. Go to the menu Tools "> Content. Uncheck Enable JavaScript.

Is JavaScript needed for Selenium?

JavaScript is a programming language that interacts with HTML in a browser, and to use this function in Selenium, JavascriptExecutor is required.

How do I disable Selenium?

Firstly, we have to create an object of the Options class. Then apply the set_preference method on that object. For disabling the JavaScript, we shall set the browser parameter javascript. enabled to False.


1 Answers

This is a way to do it if you use WebDriver with FireFox:

FirefoxProfile p = new FirefoxProfile(); p.setPreference("javascript.enabled", false); driver = new FirefoxDriver(p); 
like image 51
Assaf Shemesh Avatar answered Sep 28 '22 03:09

Assaf Shemesh