title: Selenium Python- How to handle NoSuchWindowException in Chrome
body: <p>I am trying to automate an application that downloads files automatically. I am using Selenium with Python. But my application crashes after some time throwing the <code>Aw, Snap</code> error and my script stops showing the error message: </p>
  
  <blockquote>
    <p>NoSuchWindowException: no such window: target window already closed</p>
  </blockquote>
  
  <p>So my ideas was to restart the application by including the except statement as shown: </p>
  
  <pre><code>except NoSuchWindowException as ex4:
      print("Exception4 has been thrown"+str(ex4))
      driver.refresh()
      driver.implicitly_wait(20)
      username=driver.find_element_by_id("user")
      username.clear()
      username.send_keys("")
      password=driver.find_element_by_id("pw")
      password.clear()
      password.send_keys("")
      driver.implicitly_wait(20)
      login=driver.find_element_by_id("loginButton")
      login.click() 
  </code></pre>
  
  <p>I have tried the following in my <code>except</code> clause but didn't work : </p>
  
  <ol>
  <li><code>driver.refresh()</code></li>
  <li>Click on back button: 
   <code>driver.execute_script("window.history.go(-1)")</code></li>
  <li><code>driver.get("URL")</code></li>
  <li><code>driver.quit</code>
   This worked but when I tried to relaunch the application using <code>driver.get("URL")</code> , I got the below error: </li>
  </ol>
  
  <blockquote>
    <p>"error: [Errno 10061] No connection could be made because the target machine actively refused it"</p>
  </blockquote>
  
  <p>Please suggest how I can resolve this issue. 
  Below is the error image: 
  <a href="https://i.stack.imgur.com/jprlA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jprlA.png" alt="enter image description here"></a></p>
  
  <p>Thanks</p>