问题
In my efforts to improve performance of my selenium testing application I was wondering if it is possible to avoid loading certain files such as images (jpg and png). The parameter "--disable-images" disable all images, including "gif", which in my canse can be a google analytics tag, and I must capture that.
回答1:
Yes, you can do it by specifying profile.managed_default_content_settings.image
in ChromeOptions
. Example:
chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2}
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chromeOptions)
As for only for specific image formats, I don't think it's possible
来源:https://stackoverflow.com/questions/49757073/is-it-possible-to-disable-loading-images-jpg-and-png-only-on-selenium-and-chro