Selenium (from Python) hangs if I close my browser window
Question: If I start Selenium from Python and close the browser window, my script hangs
the next time I try to get the WebDriver to do something. Note that I'm
closing the browser _window_ while leaving the browser itself open--I'm on a
Mac, and it's possible for the browser (Chrome, in my case) to remain open
even without any windows. Here's an example:

    
    
    import time
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("http://www.stackoverflow.com/")
    time.sleep(5) # Let's say we close Chrome window during this time
    print "Trying to open second page"
    driver.get("http://www.python.org/")
    print "You won't get here if you closed the Chrome window"
    

Ideally I'd like Selenium to either make a new window for me or let me tell
that there's no open window and let me create one myself.


Answer: That is not what is going to happen. The browser windows you see are not all
able to get talked to by selenium.

Selenium spawns a browser with the w3c component running and able to be talked
to. This is kind of like a mini http server that lives in the web browser,
that selenium talks to to click on things and do it's business. It's called
WebDriver. <http://www.w3.org/TR/webdriver/>

When you close the browser opened and interfaced with selenium... you are
breaking the socket connections selenium made, and it can not find it.

AFAIK: Selenium is just talking to the webdriver interface of the browser.

Your program would have to look for active browsers, get their memory address,
open a new selenium-webdriver and point it at it... this would take a bit of
re-writing the selenium source as calling a webdriver now initiates a new
browser instance.

