Python - Session is lost every time I call driver.get(url)

1,387 views
Skip to first unread message

Travis Beauvais

unread,
Jul 30, 2014, 5:05:49 PM7/30/14
to seleniu...@googlegroups.com
I have a single instance of a chrome.WebDriver. I call get('http://domain.com/') to navigate to the main page of my site. I then login, do some other things and then call get('http://domain.com/') again to go back to the main page. The problem is, after the second get() call, I've lost the session and am no longer signed in. Is this expected behavior? Another way to do what I'm doing? An option I'm missing?

Samantha Zeitlin

unread,
Aug 8, 2014, 3:26:41 PM8/8/14
to seleniu...@googlegroups.com

Samantha Zeitlin

unread,
Aug 8, 2014, 4:27:35 PM8/8/14
to seleniu...@googlegroups.com
actually, I just refactored my code and now it seems to not be doing it anymore (?). I ended up putting the login information & a time delay inside a try: except: and it seems to not be needing to log in each time anymore! 

My code before was in separate login and looping functions, roughly like this (sorry for the silly pseudocode, I don't know why Chrome is not letting me paste text into this box?):

def login_fcn():
     browser.get(url)
     find username element
     give it the username
     find password element
     time.sleep(5)
     return browser

def loop_url_list(browser):
    for item in url_list:
        browser.get(item)
        do something

That wasn't working because it was logging out and couldn't log back in each time. So I refactored and now it looks more like this: 
     
def log_in_and_do_stuff():
   browser = webdriver.Firefox()
   for url in url_list:
        browser.get(url)
        try:
            (same login and password stuff as above)
        except selenium.common.exceptions.ElementNotVisibleException:
             print "don't need to log back in again, going on"
        do some other stuff

hope that helps - 

sam



On Wednesday, July 30, 2014 2:05:49 PM UTC-7, Travis Beauvais wrote:
Reply all
Reply to author
Forward
0 new messages