问题
So my understanding is that calling driver.quit or close is the the proper way to close the driver and associated window.
However when running my tests, it seems that even without calling driver.quit and instead calling pass, that the window still closes.
I'm using python with unittest test cases excuted via pytest. I've also run standard unitests via Pycharm. In all scenarios, the browser closes as described. I want the browser to stay open to where I can debug tests. I could just call sleep(9000) but that seems dumb.
Furthermore, the browser stays open when commenting out quit on some machines, but not on others with the same chromedriver, Chrome version, and code.
Analyzing the chromedriver logs, it seems it registers a QuitAll command, but I have no idea where it could be getting it from. Could the pyc file not be overwritten?
Code for quit:
def tearDown(self):
pass
# self.driver.quit()
回答1:
The service will stop once your script ends due to the code here.
If you want chrome and chromedriver to stay open afterward, you can add the detach
option when starting chromedriver:
from selenium.webdriver import ChromeOptions, Chrome
opts = ChromeOptions()
opts.add_experimental_option("detach", True)
driver = Chrome(chrome_options=opts)
来源:https://stackoverflow.com/questions/43612340/chromedriver-closing-after-test