How to open chrome default profile with selenium?

Rest AssuredDynamic ProgrammingProgramming

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

raja
Updated on 17-Nov-2021 12:16:00

Advertisements