
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- State the differences between close() and quit()
- What are the differences between findElement() and findElements() methods in Selenium with python?
- 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 get() and navigate() methods?
- what are the differences between unshift() and push() methods in javascript?
- What are the differences between compareTo() and compare() methods in Java?
- What are the differences between class methods and class members in C#?
- What are the differences between json and simplejson Python modules?
- Differences Between Selenium and Cucumber
- What are the different cookies methods in Selenium?
Advertisements