title: How do I stop Selenium from closing the driver during execution?
body: <p>I am trying to learn Selenium to scrape some Javascript heavy websites. I can locate and extract information just fine. However, I find that for some sites I need to switch my user agent. I did it the following way to test it:</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  from fake_useragent import UserAgent 
  
  
  PATH =&quot;C:/my/path/to/chromedriver.exe&quot;
  
  ua = UserAgent()
  userAgent = ua.random
  print(userAgent)
  
  options = Options()
  options.add_argument(f'user-agent={userAgent}')
  driver = webdriver.Chrome(chrome_options=options, executable_path=PATH)
  
  driver.get(&quot;https://www.whatismybrowser.com/detect/what-is-my-user-agent&quot;)
  </code></pre>
  <p>The code works and my user agent is switched, however there is one bug that occurs now which did not occur before. The webdriver/browser (Chrome driver) automatically closes after displaying the website for a second without me specifying the <code>driver.quit()</code> argument. When I do not switch my user agent it does not close unless I do and I want to study the page a bit before closing it. I have tried to wait using <code>time.sleep()</code> but this doesn't work.</p>
  <p>How can I make the webdriver not close until specified?</p>
  <p>Answers are greatly appreciated, preferably with a code example of how to implement the solution.</p>