Pressing Browser’s Refresh Button – Selenium

Contents

Pressing the Browser’s Refresh Button

To simulate pressing of the browser’s refresh button to reload the page using Selenium for Python, call refresh() method on the Web Driver object.

driver.refresh()

Example

  1. Initialise Chrome Web Driver object as driver.
  2. Get the URL https://pythonexamples.org/ using web driver object.
  3. Press browser’s refresh button using driver.refresh().

Python Program

from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.common.by import By

service = Service(executable_path="/usr/local/bin/chromedriver")

# Initialize web driver
with webdriver.Chrome(service=service) as driver:
    #navigate to the url
    driver.get('https://pythonexamples.org/')
    #press on browser's refresh button
    driver.refresh()

Screenshots

Navigation Step #1 : Get the URL https://pythonexamples.org/.

Pressing Browser's Refresh Button - Selenium

Navigation Step #2 : Find OpenCV link and click on it.

Pressing Browser's Refresh Button - Selenium

Summary

In this Python Selenium Tutorial, we learned how to press the browser’s refresh button programmatically using driver.refresh() method.

Related Tutorials

Quiz on Selenium

Q1. What is a web driver in Selenium Python?

Not answered

Q2. Which of the following is not a popular web driver used in Selenium Python?

Not answered

Q3. What is the method used to interact with web elements in Selenium Python?

Not answered

Q4. Which of the following is not a commonly used assertion method in Selenium Python?

Not answered

Q5. Which of the following is not a commonly used web element locator in Selenium Python?

Not answered
Code copied to clipboard successfully 👍