Sometimes, we want to make Python Selenium interact with an existing browser session.
In this article, we’ll look at how to make Python Selenium interact with an existing browser session.
How to make Python Selenium interact with an existing browser session?
To make Python Selenium interact with an existing browser session, we open the driver and the connect to the session with the given session ID.
For instance, we write
driver = webdriver.Firefox()
url = driver.command_executor._url
session_id = driver.session_id
driver = webdriver.Remote(command_executor=url,desired_capabilities={})
driver.close()
driver.session_id = session_id
driver.get("http://www.example.com")
to open the driver with
driver = webdriver.Firefox()
We get the ID of the existing session with
url = driver.command_executor._url
session_id = driver.session_id
Then we close the driver and connect to it with the session with
driver = webdriver.Remote(command_executor=url,desired_capabilities={})
driver.close()
driver.session_id = session_id
Conclusion
To make Python Selenium interact with an existing browser session, we open the driver and the connect to the session with the given session ID.