- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to close a browser session in Selenium with python?
We can close a browser session in Selenium by the following ways −
Using the close() method.
Using the quit() method.
Both these methods close the browser, but close() the browser in focus and quit() ends the driver session.
Example
Code Implementation with close().
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser 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://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() #to close the browser driver.close()
Code Implementation with quit().
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser 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://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() #to end the driver session driver.quit()
- Related Articles
- Can Selenium interact with an existing browser session?
- How to close active/current tab without closing the browser in Selenium-Python?
- How to close child browser window in Selenium WebDriver using Java?
- How to Close Browser Tabs With a Keyboard Shortcut?
- How to invoke the Chrome browser in Selenium with python?
- How to invoke the Firefox browser in Selenium with python?
- How to invoke the IE browser in Selenium with python?
- How to perform back and refresh in a browser in Selenium with python?
- How to start selenium browser with proxy?
- How to refresh a browser then navigate to a new page with Javascript executor in Selenium with python?
- How to launch Edge browser with Selenium Webdriver?
- Python selenium browser driver.back().
- How to do session handling in Selenium Webdriver?
- How to switch different browser tabs using Python Selenium?
- Browser Plugin Testing With Selenium.

Advertisements