Whenever I call driver.quit()
it waits for the website to first complete loading then it closes the browser, is there any way I can force close the browser immediately?
Asked
Active
Viewed 394 times
0

undetected Selenium
- 183,867
- 41
- 278
- 352
-
1there's pageloadstrategy, but setting that will have other consequences... why would you go to a URL and then quit? – pcalkins Nov 16 '21 at 17:19
-
@pcalkins incase I have to abort the entire process in between, I mean we humans do it all the time I don't see why selenium can't do it too ;P – Nov 16 '21 at 17:19
-
Sample code? My first guess is that the command to open the website finishes when the page is loaded. So the quit() simply needs to wait on the .get() to finish – Taco Verhagen Nov 16 '21 at 17:21
-
@TacoVerhagen yea you're right just a simple .get() and an async .quit() in another function, actually I'm forking selenium from another process so the entire code would be a little difficult but you have the right idea – Nov 16 '21 at 17:23
-
it'll wait for pageready state to return from wire protocol unless pageloadstrategy is set to none. – pcalkins Nov 16 '21 at 18:07
1 Answers
1
When you invoke get()
for an url
using Selenium a lot many actions happens under the hood, including HTTP requests received by geckodriver, packets sent to and from the remote protocol in Firefox, and responses sent back to your client.
Once the basic mandatory requests/responses are successfully completed, based on the pageLoadStrategy the browser i.e. the client sends back the program control to Selenium to perform the next line of code.
Now pageLoadStrategy
can be either of the following:
- normail: This stategy causes Selenium to wait for the full page loading (html content and subresources downloaded and parsed).
- eager: This stategy causes Selenium to wait for the DOMContentLoaded event (html content downloaded and parsed only).
- none: This strategy causes Selenium to return immediately after the initial page content is fully received (html content downloaded).
So once the program control is returned back to Selenium based on pageLoadStrategy which is somewhat timebound, then only driver.quit()
can be performed.

undetected Selenium
- 183,867
- 41
- 278
- 352