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/
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.
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.
JavaScript is a programming language that interacts with HTML in a browser, and to use this function in Selenium, JavascriptExecutor is required.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With