Selenium uses the default Chrome Profile

Selenium 13 ต.ค. 2021

If you want to open a Chrome Browsing Session, here are the following options:

To use the default Chrome Profile:

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

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
  • Note: Your default chrome profile would contain a lot of bookmarks, extensions, theme, cookies etc. Selenium may fail to load it. So as per the best practices create a new chrome profile for your @Test and store/save/configure within the profile the required data.
  • To use the customized Chrome Profile:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")

Here you will find a detailed discussion on:

https://stackoverflow.com/questions/49270109/how-to-open-a-chrome-profile-through-python

https://stackoverflow.com/questions/52394408/how-to-use-chrome-profile-in-selenium-webdriver-python-3

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.