- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Advertisements