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

Patricia Arquette
Release: 2024-10-27 06:00:04
Original
373 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!