0

I want to use my local chrome with selenium, but every time I just get a new chrome without any cookies

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

option = webdriver.ChromeOptions()
option.add_argument(r'--user-data-dir=/Users/mac/Library/Application Support/Google/Chrome/Default') 
driver = webdriver.Chrome(chrome_options=option, executable_path="/usr/local/bin/chromedriver")
driver.get("https://twitter.com/")
  • my chrome user data dir

enter image description here

I want to use default chrome with selenium, then how to setup chrome options?

Please help, thanks!

2 Answers 2

2

You have to mention the Chrome profile directory like below:

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

option = webdriver.ChromeOptions()

option.add_argument(r"user-data-dir=/Users/mac/Library/Application Support/Google/Chrome/")
option.add_argument("--profile-directory=Default")

driver = webdriver.Chrome(chrome_options=option, executable_path="/usr/local/bin/chromedriver")
driver.get("https://twitter.com/")

Before executing the code, close all the Chrome browser windows and chromedriver.exe then try.

Sign up to request clarification or add additional context in comments.

1 Comment

It works. Thanks. I need to close all the chrome browser.
0

First, install this chrome package

pip install undetected-chromedriver

then, you can load profiles, plugins, and customize settings very easily.

import undetected_chromedriver as uc

if __name__ == '__main__':
    options = uc.ChromeOptions()
    options.add_argument(f'--user-data-dir=c:\\temp\\chrome-profile') # chrome profile location
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
    options.add_argument('--load-extension=C:\\temp\\plugin-folder')
    driver = uc.Chrome(options=options)
    driver.get('https://www.google.com')
    driver.quit()

1 Comment

I had tried as your code use undetected_chromedriver and set user-data-dir=/Users/mac/Library/Application Support/Google/Chrome/Default, but it also open new chrome, not the default one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.