I have two functions using selenium webdriver. One logs in, and another that performs authenticated actions on the website.
from selenium import webdriver
def login(driver):
driver.get('website.com')
# login
return driver
def do_stuff(driver):
driver.get('website.com/things')
# do stuff
return driver
if __name__ == '__main__':
driver = webdriver.Firefox()
driver = login(driver)
driver = do_stuff(driver)
driver.close()
The first function successfully logs in, but when the second function runs, I get the following error:
selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection
I checked the session_id
of the driver at the end of the first function and at the beginning of the first function, and they are the same. Also, it should not be an issue with the specific commands in the script, because it works when not split into two functions. I can provide a more specific code sample if it helps.
What am I missing, is there a way to get this to work?