0

So I have a use case where the system I'm trying to connect to requires a full sign in and text message validation every time a new browser is launched. I want to have the user log in once and then until they close that browser window they can continue to send automation to the same window.

First function opens the site and saves some session details, the user could then log in, etc. Currently I'm saving the command_executor._url and the sesion_id for future use to a json

from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
import json


url = "http://www.stackoverflow.com"

opt = Options()
opt.add_experimental_option("detach",True)


swd = Chrome(options=opt)
swd.get(url)


session = {'url':swd.command_executor._url,'id':swd.session_id}

with open('session.json','w') as file:
    json.dump(session,file)

Second function I'd like to be able to grab the existing window and do some actions.

from selenium.webdriver import Remote
from selenium.webdriver.chrome.options import Options
import json

with open("session.json","r") as file:
    session = json.load(file)

opt = Options()
opt.add_experimental_option("debuggerAddress",session['url'])

swd = Remote(command_executor=session['url'],options=opt)

#do some actions 

swd.quit()

It seems like I'm doing something wrong but I have no idea what to change. I know there a few threads talking about this but it seems like all of them are out of date or for different situations

Here is the error i'm getting:

raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=#####): Max retries exceeded with url: /session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

ABrunette
  • 1
  • 1
  • Does this answer your question? [Can Selenium interact with an existing browser session?](https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session) – JonSG Aug 16 '23 at 15:23
  • It seems like stuff has changed since then - the desired_capabilities={} doesnt seem to exist anymore. This post was one of my starting points. – ABrunette Aug 16 '23 at 15:46

0 Answers0