Using profile with selenium closes current browser window with different profile

27 Views Asked by At

I am trying to run selenium using profile. I know that if a profile is already opened normally on a browser, opening the same via selenium will be erroneous. So I made a second profile and am trying to open it (via selenium) while running the first profile in a normal browser window.

But the problem is that running the code first closes the current browser window and then opens the second profile.

Here is the code

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

options = Options()
options.binary_location = '/snap/brave/current/opt/brave.com/brave/brave'
options.add_argument("--user-data-dir=/home/dhruv/snap/brave/current/.config/BraveSoftware/Brave-Browser/")
options.add_argument("--profile-directory=Profile 1")
options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(options=options)

try :
    print("Driver created")
    print("Sleeping")
    sleep(50)
    driver.get("brave://settings/appearance")
    driver.get_screenshot_as_file("screenshot1.png")
finally :
    driver.close()

I am using brave browser with chromium version 116.0.5845.180, chromedriver version 116.0.5845.96 and selenium version 4.11.2.

Here is a video. Notice how the first browser closes at 0:02.

0

There are 0 best solutions below