How to get chrome webdriver selenium path to profile files in python?

Question:

I need "profile path" from chrome://version/ to download files from this profile.

I tried using

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

but it only showed {‘browserName’: ‘chrome’} .

Asked By: Xubiz

||

Answers:

Just navigate to that page and retrieve the element you are looking for.

I will insert a complete code explaining step by step.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# It is not mandatory to specify all this, but it is strongly recommended for any web scraping software
opts = Options()

# make web scraping 'invisible'
opts.add_argument("--headless")
opts.add_argument('--no-sandbox')

user_agent = "user-agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36]"
opts.add_argument(user_agent)

# ChromeDriverManager ensures no webdriver recovery issues under any supported operating system
# If you don't like this way, use the classic webdriver with the system path
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opts)

browser.get('chrome://version/')
element = browser.find_element(By.ID, "profile_path")

print(element.text)

output, in my case, will be:

C:UsersgiuseAppDataLocalTempscoped_dir16096_1379017973Default
Answered By: Giuseppe La Gualano