Home > Article > Web Front-end > How to Disable CSS in Python Selenium Using ChromeDriver with ChromeOptions?
Disable CSS in Python Selenium Using ChromeDriver with ChromeOptions
In the pursuit of optimizing webpage loading speed, you may encounter the need to disable CSS to eliminate unnecessary rendering. While you've successfully employed the prefs dictionary to disable images and JavaScript, attempts to replicate this functionality for CSS have proven ineffective.
Solution:
To successfully disable CSS using ChromeOptions, you must target the profile.default_content_setting_values key within the prefs dictionary. This key allows you to modify the default behavior of various content settings. To disable CSS, simply add it to the list of disabled settings:
prefs = {'profile.default_content_setting_values': {'images': 2, 'javascript': 2, 'css': 2}}
By incorporating this modification into your existing code, you will effectively disable CSS in ChromeDriver for improved loading times.
option = webdriver.ChromeOptions() prefs = {'profile.default_content_setting_values': {'images': 2, 'javascript': 2, 'css': 2}} option.add_experimental_option('prefs', prefs) driver = webdriver.Chrome(chrome_options = option)
The above is the detailed content of How to Disable CSS in Python Selenium Using ChromeDriver with ChromeOptions?. For more information, please follow other related articles on the PHP Chinese website!