Why driver.get doesn't work in Python Selenium when using Profile

359 views Asked by At

What I need

I need to run Selenium with Chrome Profile Here is my code:

from selenium import webdriver
import time

options = webdriver.ChromeOptions() 
options.add_argument("--user-data-dir=/home/atom/.config/google-chrome") #Path to your chrome profile
options.add_argument('--profile-directory=Profile 1')
driver = webdriver.Chrome(options=options)

driver.get('https://youtube.com')
time.sleep(5)

Problem

The code opens Google Chrome instead of Chromedriver. Profile is loaded. But driver.get doesn't work

Question

How can I use Selenium with Chrome profile?

1

There are 1 answers

0
Jeff On

What chromedriver does is briefly described here. When you call get on the webdriver, you are asking for the site to be opened on the chrome browser. If you want to use brave browser or another browser implementation using the chromium engine, you may specify the location of the browser's binary using:

ChromeOptions options = new ChromeOptions();

options.setBinary("/path/to/other/chrome/binary");

You may load a specific profile by using:

ChromeOptions options = new ChromeOptions();

options.addArguments("user-data-dir=/path/to/your/custom/profile");

Specifying no profile (not including this option should load the default profile).

A complete list of supported options may be found here.