Some time ago I came across a new, unusual feature of Selenium. After running the tests with Python, the browser closes on its own, even though the
driver.quit() command is missing. This new feature is hard to notice when you’re maintaining an old project. When creating a new project, you may decide to leave the browser open, but it will close.
At first, I decided to just put up with it. In the moments when I needed to leave the browser open after running the tests, I added slips for a minute or so. But, in the end, I decided to figure out how to deal with it.
It turned out that this feature was added intentionally so that after the program ends, the system returns to the same state that it was before.
But the good news is that you don’t have to put up with it. It is possible to return everything as it was before. To do this, chrome has an experimental option called “detach”. To enable this, do this:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option('detach', True) chrome_driver = webdriver.Chrome()
After that you will be able to work as usual:
driver.get('https://www.google.com') driver.find_element(....) .... driver.quit()