Is it possible to disable loading images (jpg and png only) on Selenium and Chrome webdrive?

故事扮演 提交于 2021-02-08 05:12:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!