
That's because upon initiating the driver, the selenium library automatically starts a new session for it - and now you have 1 webdriver process with 2 sessions (browsers instances). When that is ran, you'll see a new browser window being opened. # when the started selenium is a local one, the url is in the form ''

With those two properties now known, another instance can connect the "trick" is to initiate a Remote driver, and provide the _url above - thus it will connect to that running selenium process: driver2 = webdriver.Remote(command_executor=the_known_url) # command_executor._url (it's "private", not for a direct usage), and session_id # now Google is opened, the browser is fully functional print the two properties When a webdriver instance is initiated, you need to get the before-mentioned properties sample: from selenium import webdriver not implementedĪ selenium webdriver session is represented by a connection url and session_id, you just reconnect to an existing one.ĭisclaimer - the approach is using selenium internal properties ("private", in a way), which may change in new releases you'd better not use it for production code it's better not to be used against remote SE (yours hub, or provider like BrowserStack/Sauce Labs), because of a caveat/resource drainage explained at the end. firefox and google-chrome needs to be started in a specific mode and configuration, which effectively means that justĪttaching to a running instance isn't technically possible.With internet-explorer, it's possible to iterate over the open windows in the OS and find the right IE process to attach to.

Reconnecting to an existing Browsing Context is a browser specific feature, hence can't be implemented in a generic way.In the discussion Allow webdriver to attach to a running browser Simon Stewart clearly mentioned: There had been a lot of discussions and attempts around to reconnect WebDriver to an existing running Browsing Context.

Even if you are able to extract the Session ID, Cookies and other session attributes from the previous Browsing Context still you won't be able to pass those attributes as a HOOK to the WebDriver.Ī cleaner way would be to call webdriver.quit() and then span a new Browsing Context. No, you can't reconnect to the previous Web Browsing Session after you quit the script.
