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("https://daztech.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("https://daztech.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("https://daztech.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("https://daztech.com/")
driver.quit()
Hopefully this article has been useful for you to learn how to close the browser when using Selenium in Python.