drerD
drerD

Reputation: 689

How to reuse preloaded images with Selenium in Chrome driver?

I am using the Selenium framework with Python, I am trying to save bandwidth while doing automation by reusing the images preloaded in the Chrome webdriver in my Python code. I am able to access the source url of the images, so far I am just re-donwloading them again with requests. I know for certain that normal browsers save images to temporary location on hard drive, and I guess Chrome webdriver does the same. How do I access these files with Selenium given that I know the src?

Upvotes: 1

Views: 2981

Answers (1)

Or Duan
Or Duan

Reputation: 13810

You should reuse your chrome profile, something like that:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\path\\to\\your\\profile")  # Path to your chrome profile
driver = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)

About the path, this can be done by going to chrome://version/ in your chrome, one of the settings there is your path, this will reuse your chrome profile, you might need to remove the last directory from the path if it's Default directory.

If you want your own profile that is not connected to your chrome, you can specify any path you want, and selenium will create it for you.

Upvotes: 2

Related Questions