![]() Print("No Driver window open - make a new one")ĭriver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=myoptions)Įxecutor_url = mand_executor. Print(" Driver has an active window we have connected to it and running here now : ") #Try to connect to the last opened session - if failing open new windowĭriver = attach_to_session(executor_url,session_id) # Replace the patched function with original function It's just striking that the driver does not let a person specify a timeout to cater for when the remote is still starting. # command_executor._url (it's "private", not for a direct usage), and session_id My suspicion is that either the socket cannot connect because the selenium server is still starting itself on the other end, or, less likely the local end is still resolving the remote ip from it's name. ![]() # 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. ![]()
0 Comments
Leave a Reply. |