- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the differences between close() and quit() methods in Selenium with python?
There may be situations when we need to open more than browsers with multiple tabs. In order to close these sessions quit() and close() methods are used in Selenium. However there are differences between them, they are listed below −
The close() method can close the browser in focus. While quit() method works with the driver.dispose() method that closes every successive window.
The close() method closes the present window on which we are working. While quit() method suspends all the driver sessions and instances, thereby closing each opened window.
Example
Code Implementation with close() method.
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://the-internet.herokuapp.com/windows") #to refresh the browser driver.refresh() driver.find_element_by_link_text("Click Here").click() #to fetch the first child window handle chwnd = driver.window_handles[1] #to switch focus the first child window handle driver.switch_to.window(chwnd) #to close the first child window in focus driver.close()
Code Implementation with quit() method.
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://the-internet.herokuapp.com/windows") #to refresh the browser driver.refresh() driver.find_element_by_link_text("Click Here").click() #to fetch the first child window handle chwnd = driver.window_handles[1] #to switch focus the first child window handle driver.switch_to.window(chwnd) #to close the all the windows driver.quit()
- Related Articles
- What are the differences between switch_to_default_content() and switch_to.parent_frame() methods in Selenium with python?
- What are the differences between current_window_handle and window_handles methods in Selenium with python?
- What are the differences between readline() and readlines() in Selenium with python?
- What are the differences between xpath and css in Selenium with python?
- What are the differences between implicit and explicit waits in Selenium with python?
- What are the differences between findElement() and findElements() methods?
- what are the differences between unshift() and push() methods in javascript?
- What are the differences between class methods and class members in C#?
- What are the differences between compareTo() and compare() methods in Java?\n
- What are the methods available for handling static dropdowns in a page in Selenium with python?
- How to close a browser session in Selenium with python?
- What are the common driver methods that can be applied to browsers in Selenium with python?
- What are the differences between Python and an Anaconda?
- What are the different cookies methods in Selenium?
- Differences Between Selenium and Cucumber

Advertisements