Selenium multiple Firefox error: session is already started

123 Views Asked by At

I'm using Python, Selenium and Ubuntu 22.04. I can open several Chrome windows, but when I try to do the same using Firefox I just get this error after opening the first window:

selenium.common.exceptions.SessionNotCreatedException: Message: Session is already started

I tried to make this code similar to the Chrome one: create a driver with a different profile for each Firefox instance:

geckodriver_path = "/snap/bin/geckodriver"
driver_service = Service(executable_path=geckodriver_path)
options = [] * 10
drivers = [] * 10

for x in range(0, 10):
    options[x] = Options()
    options[x].add_argument('-profile')
    options[x].add_argument(dir + profile[x])
    drivers[x] = webdriver.Firefox(service = driver_service, options=options[x])

I've also tried to use:

options[x].profile = FirefoxProfile(dir + perfil[x])

instead of:

options[x].add_argument('-profile')
options[x].add_argument(dir + profile[x])

but I still get the same error.

The "dir + profile[x]" seems to work fine, because I can open one Firefox window for the first profile and the folder gets filled. The problem is when I try to open more than 1 Firefox window. Please let me know if you have a solution for this. :)

0

There are 0 best solutions below