How to use close() and quit() method in Selenium Python ?
Last Updated :
06 Mar, 2020
While doing stuff with selenium multiple browsers with multiple tabs will normally opens in order to close these tabs close()
and quit()
methods are used. close()
method is used to close the current browser window on which the focus is set, on the other hand quit()
method essentially calls the driver.dispose method that successively closes all the browser windows and ends the WebDriver session graciously.
Syntax :
driver.close()
driver.quit()
Argument :
Both methods takes no argument
Action performed :
close()
method closes the current window.
quit()
method quits the driver instance, closing every associated window, which is opened.
Code for close method() :
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url)
driver.close()
|
Output : The webpage will loaded then closes due to close() method.
Code for quit() method:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url)
driver.quit()
|
Output : The webpage will be loaded then window get quit due to quit() method.
Share your thoughts in the comments
Please Login to comment...