- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to disable Javascript when using Selenium?
We can disable JavaScript using Selenium webdriver. We have to use the Options class to achieve this task. 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. Also this information should be passed to the driver object.
Syntax
op = Options() op.set_preference('javascript.enabled', False)
We can get the javascript.enabled parameter of the browser by following the below steps −
Open a browser.
Type about:config in browser address.
Enter javascript in the search bar.
Example
from selenium import webdriver from selenium.webdriver.firefox.options import Options #object of Options class op = Options() #disable JavaScript op.set_preference('javascript.enabled', False) #set geckodriver.exe path driver = webdriver.Firefox(executable_path="C:\geckodriver.exe", options=op) driver.maximize_window() #launch about:config driver.get("about:config")
Output
- Related Articles
- How to Disable Radio Buttons using JavaScript?
- How to Disable images in Selenium Google ChromeDriver?
- How to disable resizable property of textarea using JavaScript?
- How to disable default behavior of when you press enter with JavaScript?
- How to disable mouse event on certain elements using JavaScript?
- How to disable right-clicking on a website using JavaScript?
- How to disable JavaScript in Firefox?
- How to disable JavaScript in Opera?
- How to execute a Javascript using Selenium in Python?
- Disable images in Selenium Google ChromeDriver.
- How to disable right click using jQuery?
- How to disable JavaScript in Internet Explorer (IE)?
- How to disable future dates in JavaScript Datepicker?
- How to get html with javascript rendered sourcecode by using Selenium?
- How to find Elements in a Webpage using JavaScript in Selenium?

Advertisements