How can I disable Java Script in Selenium's Chrome Driver using python
New Selenium IDE 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.
We can stop a page loading with Selenium webdriver in Chrome browser by using the JavaScript Executor. Selenium can execute JavaScript commands with the help of the executeScript command. To stop a page loading, the command window. stop() is passed as a parameter to the executeScript method.
Disabling JavaScript
in Chrome
is possible with old ChromeDriver
prior to ChromeDriver2
, which only supports Chrome 28 or under. try as below :-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-javascript")
driver = webdriver.Chrome(chrome_options=chrome_options)
WARNING: Running without
JavaScript
is unsupported and will likely break a large portion of theChromeDriver's
functionality. I suspect you will be able to do little more than navigate to a page. This is NOT a supported use case, and we will not be supporting it.
Hope it will help you...:)
It's Really easy ! Just try this code !
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option( "prefs",{'profile.managed_default_content_settings.javascript': 2})
chrome = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
chrome.get('http://stackoverflow.com/')
If you want to disable Images, just replace javascript with image.
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