How to Close a Web Browser using the Selenium Module in Python



Python


In this article, we show how to close a web browser using the selenium module in Python.

So the selenium module in Python is a very dynamic and useful module when working with web browsers such as Firefox or Chrome.

Using the selenium module, we can open up a browser, go to any URL we need to go to, and do things such as enter text into text boxes, submit forms, and close the web browser.

We can close a web browser using the selenium module using the quit() function.

This is shown in the following code below.



The quit() function works just like the Close ('X') button in a web browser. It closes the entire window and the window disappears from view.

We will now go over an example of full code in which we open the Firefox web browser, go to the walmart web page, and then we close the browser window.



So we open the Firefox web browser and go the walmart home page.

We then close the window using the browser.quit() function.

This will close the web browser, which then vanishes from view, just as it would if you pressed the red 'X' button on the top right corner of a web browser.

This is how you can simulate the Close 'X' button of a web browser.

And this is how you can close a web browser using the Selenium module in Python.


Related Resources

How to Create a Zip File in Python

How to Extract All Files and Folders from a Zip File in Python

How to Read the Contents of a Zip File in Python



HTML Comment Box is loading comments...