I want to organize work with several windows in parallel from one driver, but at any access to the driver object from more than one stream, an error occurs. Is it possible to do such a trick at all?

import os from selenium import webdriver drive = "C:\\chromedriver.exe" os.environ["webdriver.chrome.driver"] = drive driver = webdriver.Chrome(drive) class dv: def __init__(self,driver): self.driver = driver def get(self): print self.driver.current_url dvr = dv(driver) t1 = Thread(target = lambda: dvr.get()) t2 = Thread(target = lambda: dvr.get()) t1.start() t2.start() 

Even if we organize a strict queue of access to the driver through the Queue, the situation is almost the same, an error still occurs in one of the threads

  • what a mistake? What prevents your browser from running in each thread? - jfs

1 answer 1

It is an expected error. You are trying to work with the object from the first thread from other threads.

You need to work with different windows not from one driver instance, but from several. Then the problem will be solved. For each thread - its own instance of the driver.