Syntax error How to open chrome default profile with selenium?

How to open chrome default profile with selenium?



We can open Chrome default profile with Selenium. To get the Chrome profile path, we need to input chrome://version/ in the Chrome browser and then press enter.

We need to use the ChromeOptions class to open the default Chrome profile. We need to use the add_argument method to specify the path of the Chrome profile.

Syntax

o = webdriver.ChromeOptions()
o.add_argument = {'user-data-dir':'/Users/Application/Chrome/Default'}

Example

Code Implementation

from selenium import webdriver
#object of ChromeOptions class
o = webdriver.ChromeOptions()
#adding Chrome Profile Path
o.add_argument = {'user-data-dir':'/Users/Application/Chrome/Default'}
#set chromedriver.exe path
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", options=o)
#maximize browser
driver.maximize_window()
#launch URL
driver.get("https://www.tutorialspoint.com/index.htm")
#get browser title
print(driver.title)
#quit browser
driver.quit()

Output

Updated on: 2021-11-17T12:16:00+05:30

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements