Reputation: 373
I have a python script that scraps data off from a website on an hourly basis. It is stored on the server at the moment and is working well as I am using task scheduler to schedule it to execute the script on an hourly basis.
I am using this code
driver.quit()
to quit the browser window
My problem to this that whenever I am not logging in to the server, it will start stacking up the webdriver window as somehow the driver.quit() function does not work when I am logging into the server. every morning when I came to work, I have tons of window to close from the server.
I tried to quit, close, dispose, but it doesn't help. What else I can try?
Upvotes: 37
Views: 80679
Reputation: 97
You can close browser by calling JavaScript close methods like so.
driver.execute_script("window.close();")
Upvotes: 0
Reputation: 566
For anyone still finding this question relevant in 2021 (heck it is for me!).
For me driver.quit()
definitely was the right method. The main issue was tests not being cleaned up properly, meaning driver.quit()
was never called.
unittest
use the tearDown
or tearDownClass
methods (setup the driver in setUp
.driver
object in a try / catch and do the driver.quit()
in the finally
block.Upvotes: 3
Reputation: 133
Could'nt you scrape in headless mode? (example for chrome)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.headless = True
...
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.create_options()
Upvotes: 2
Reputation: 181
For Python and chromedriver I've found these two methods useful (mind the difference):
driver.close()
- closes the browser active window.
driver.quit()
- closes all browser windows and ends driver's session/process.
Upvotes: 18
Reputation: 609
In python using chromedriver, I quit Chrome processes with:
driver.close()
Upvotes: 49
Reputation: 11
I use linux command to close all. Here're two commands I ran after all scraping job is done:
Upvotes: 0
Reputation: 691
I think webDriver.Dispose()
should work, It closes all browser windows. Here is a SO post about the 3 different ways to close a webdriver.
Upvotes: -4