Home >Backend Development >Python Tutorial >How to Load the Default Chrome Profile Using Python Selenium Webdriver?

How to Load the Default Chrome Profile Using Python Selenium Webdriver?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 06:00:04459browse

How to Load the Default Chrome Profile Using Python Selenium Webdriver?

Loading the Default Profile in Chrome Using Python Selenium Webdriver

To retain cookies and website preferences across sessions, it's necessary to launch Chrome with its default profile when using Python Selenium Webdriver.

Solution:

The following code provides a solution:

<code class="python">from selenium import webdriver

# Set path to default Chrome profile (exclude trailing "\Default")
options = webdriver.ChromeOptions()
path = "C:\Users\User\AppData\Local\Google\Chrome\User Data"
options.add_argument(f"user-data-dir={path}")

# Set path tochromedriver.exe
w = webdriver.Chrome(executable_path="C:\Users\User\chromedriver.exe", chrome_options=options)</code>

Custom Profile

To create and use a separate profile for Selenium:

  1. Replace the specified path with a new, non-existing path.
  2. When Chrome launches, a new profile will be generated at the specified location.

The above is the detailed content of How to Load the Default Chrome Profile Using Python Selenium Webdriver?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn