How to refresh the page using Selenium web driver in Python

Overview

Selenium is an open-source web-based automation tool. In this Answer, we'll learn to refresh the page using Selenium in Python. We'll use the refresh() method to refresh the page.

Syntax

driver_instance.refresh()

Example

from selenium import webdriver
import time
#specify where your chrome driver present in your pc
PATH=r"C:\Users\educative\Documents\chromedriver\chromedriver.exe"
#get instance of web driver
driver = webdriver.Chrome(PATH)
#provide website url here
driver.get("https://www.educative.io/")
#sleep for 5 seconds
time.sleep(5)
#refresh the page
driver.refresh()

Explanation

  • Line 1: We import webdriver from selenium package.
  • Line 2: We import time.
  • Line 5: We provide the path where we placed the driver of the web browser. For chrome, it is chromedriver.exe in windows environment.
  • Line 8: We get the instance of the webdriver.
  • Line 11: We provide the URL to driver.get() method to open it.
  • Line 14: We make the program sleep for 5 seconds.
  • Line 17: We refresh the current page using the driver.refresh() method.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved