3

I am looking to keep the browser window open even after test execution. I would like to keep it open indefinitely. As of now , as a work around I am just using sleep() to keep the window from closing.

Any help would be much appreciated. Thank you !

Egret
  • 421
  • 1
  • 3
  • 13
  • @Prune I think the dup target [discussion](https://stackoverflow.com/questions/42044315/how-to-keep-chrome-browser-window-open-after-selenium-script-finishes-on-python) was about _re-use the same window_ while this specific question is about _keep the window from closing_, both of them seems to be different. Can you have a re-look please? – undetected Selenium Mar 15 '19 at 20:48
  • Thanks; I clicked on the wrong duplicate. This question *has* been handled many times. – Prune Mar 15 '19 at 22:08
  • 3
    Please a [mcve] that closes the browser after it's finished. I'm willing to bet you're telling it to close. – Bryan Oakley Mar 16 '19 at 15:13

3 Answers3

4

Simple - do not call Close Browser at the end.

Todor Minakov
  • 19,097
  • 3
  • 55
  • 60
3

Ideally, the WebDriver service should stop once your script ends due to this code.

However if you want Chrome and ChromeDriver to stay open afterwards, you can add the experimental option detach when initializing the chromedriver.

Through Selenium-Python client you can:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.google.com/')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

In a previous Stack Overflow question about connecting to the Chrome remote-debugging-port I provided an example for connecting to a running chrome instance using it's Dev Port.

This will functionally do what you want and as such may be an alternative to no closing as suggested by @Todor and @Bryan.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43