• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Selenium to Close Browser in Python

Using Selenium to Close Browser in Python

June 26, 2022 Leave a Comment

To close the browser when using Selenium in Python, the easiest way is to use the Selenium webdriver close() function.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

driver.close()

If you want to end the driver session, which also closes the browser, you can use the Selenium webdriver quit() function.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

driver.quit()

The Selenium Python module gives you the tools you need to be able to automate many tasks when working with web browsers.

When working with web pages, sometimes it can be useful to refresh a web page.

You can easily close the browser with Selenium in Python. The easiest way is with the Selenium webdriver close() function.

Below is a simple example of how you can use Selenium to close the browser in your Python code.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

driver.close()

If you want to end the driver session, which also closes the browser, you can use the Selenium webdriver quit() function.

from selenium import webdriver

driver = webdriver.Chrome()

driver.get("http://theprogrammingexpert.com/")

driver.quit()

Hopefully this article has been useful for you to learn how to close the browser when using Selenium in Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Check if Deque is Empty
  • 2.  Write Float to File Using Python
  • 3.  Negate Boolean in Python with not Operator
  • 4.  Read Pickle Files with pandas read_pickle Function
  • 5.  pandas Standard Deviation – Using std() to Find Standard Deviation
  • 6.  Pythagorean Theorem in Python – Calculating Length of Triangle Sides
  • 7.  How to Get the Size of a List in Python Using len() Function
  • 8.  Using Python to Check If Variable is Not None
  • 9.  Union of Lists in Python
  • 10.  Using Lambda Expression with min() in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy