---
description: During test automation of web-based application, there comes a need for the page to be refreshed multiple times for all web elements to be loaded completely. On the initial page load, some web element
title: Refresh Page using Selenium Webdriver
image: https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Refreshing a page in Selenium WebDriver reloads the current URL so that every element renders before assertions run, and the framework offers five distinct commands that achieve the same reload in different ways.

* 🔘 **Default choice:** driver.navigate().refresh() is the built-in reload and takes no arguments and returns no value.
* ☑️ **Recursive variants:** Passing getCurrentUrl() into get() or navigate().to() reloads the same address.
* ✅ **Keyboard route:** sendKeys accepts Keys.F5 or the Unicode value \\uE035, but it must target a real element.
* 🧪 **Script route:** JavascriptExecutor running location.reload() works when the WebDriver command is blocked.
* 🛠️ **After the reload:** Every element reference captured earlier becomes stale and has to be located again.
* 📊 **Modern setup:** Selenium Manager arrived in version 4.6, so the driver path no longer has to be set by hand.

[ Read More ](javascript:void%280%29;) 

![Refresh page using Selenium WebDriver commands](https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png) 

During test automation of a web-based application, there comes a need for the page to be refreshed multiple times for all web elements to be loaded completely. On the initial page load some web elements might be loaded, while it takes a second page refresh for all of them to appear. This can be done using the refresh command provided by [Selenium](https://www.guru99.com/selenium-tutorial.html) WebDriver.

## How to Refresh Page in Selenium

Browser refresh operation can be performed using the following ways in Selenium. We will discuss the below mentioned ways in detail throughout the article.

1. driver.navigate().refresh() command
2. Get method
3. Send Keys command
4. Navigate method
5. driver.navigate().to() command

## 1) driver.navigate().refresh() Command

This is the inbuilt method for performing a page refresh operation provided by Selenium WebDriver. This command is the most commonly used command across test automation for performing a page refresh operation. The refresh command can be used in a simple way as mentioned below.

driver.get("https://demo.guru99.com/selenium/guru99home/");
driver.navigate().refresh();

Navigation is an interface that is used to perform various browser operations such as navigating to the previous page, navigating to the next page, page refresh and browser close. Navigation interface methods can be accessed using the command driver.navigate(). The refresh method of the Navigation interface does not take any arguments and does not return any value.

### Example:

### Test Scenario:

1. Open the Chrome browser with the web page <https://demo.guru99.com/selenium/guru99home/>
2. Once the page is loaded successfully, refresh the web page using the driver.navigate().refresh() method
3. Close the browser using the driver.close() method

#### Code

package Guru99Demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class RefreshDemo {
public static void main(String args[]) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://demo.guru99.com/selenium/guru99home/");
driver.manage().window().maximize();
driver.navigate().refresh();
driver.close();
}
}

⚠️ **Version note:** Selenium Manager shipped with **Selenium 4.6** and downloads the matching browser driver automatically, so the System.setProperty line above is no longer required on a current version — `new ChromeDriver()` is enough. The original line is kept because it is still correct for the Selenium 3 style setup the example was written against.

**Code Output:**

On the initial page load the demo home page renders as shown below.

[](https://www.guru99.com/images/1/052819%5F0539%5FRefreshPage1.png)

After the page refresh operation the video on the page has changed, which confirms the reload actually happened.

[](https://www.guru99.com/images/1/052819%5F0539%5FRefreshPage2.png)

## Multiple Other Ways to Refresh a Page

The refresh method is not the only route to a reload. The four techniques below produce the same result and are worth knowing, because a locked-down application or a stubborn browser occasionally blocks one of them.

## 2) Get Method

The get method can be used in a recursive way to refresh a page. In order to achieve this, we need to pass another method as an argument to the get method.

**Example:**

driver.get("https://www.guru99.com");
driver.get(driver.getCurrentUrl());

## 3) Navigate Method

This method uses the same concept of recursion as mentioned above. The getCurrentUrl() method is passed as an argument to the driver.navigate().to() method.

**Example:**

driver.get("https://www.guru99.com");
driver.navigate().to(driver.getCurrentUrl());

### RELATED ARTICLES

* [What is Selenium WebDriver? ](https://www.guru99.com/introduction-webdriver-comparison-selenium-rc.html "What is Selenium WebDriver?")
* [WebElement in Selenium ](https://www.guru99.com/accessing-forms-in-webdriver.html "WebElement in Selenium")
* [Implicit and Explicit Wait in Selenium with Syntax ](https://www.guru99.com/implicit-explicit-waits-selenium.html "Implicit and Explicit Wait in Selenium with Syntax")
* [How to Select Value from Dropdown in Selenium ](https://www.guru99.com/select-option-dropdown-selenium-webdriver.html "How to Select Value from Dropdown in Selenium")

## 4) Send Keys Method Using the F5 Key

This is the second most commonly used method to refresh a page in Selenium. It takes the refresh key (F5) as an argument to the sendKeys method. Since sendKeys works only on web elements rather than on the browser, we must first identify a valid web element on the web page and then use the sendKeys method. This can be accomplished as shown below.

**Example:**

driver.get("https://www.guru99.com");
driver.findElement(By.id("username")).sendKeys(Keys.F5);

Because the keystroke is delivered to an element rather than to the browser chrome, this route depends on the element holding focus. If the [locator](https://www.guru99.com/locators-in-selenium-ide.html) matches a field that cannot take focus, the key is swallowed and the page never reloads.

## 5) Send Keys Method Using ASCII Code

This method uses the same concept as above, but instead of passing the F5 key as an argument we send the code point of the refresh key as an argument. This can be accomplished as shown below.

driver.get("https://www.guru99.com");
driver.findElement(By.id("username")).sendKeys("\uE035");

The value \\uE035 is the WebDriver Unicode code point that the protocol maps to F5, so this snippet and the previous one are equivalent.

## How to Refresh a Page Using JavaScriptExecutor

Every browser exposes a reload function to page scripts, and Selenium can call it through the JavascriptExecutor interface. This is the usual fallback when the WebDriver refresh command is intercepted by the application or by a browser extension.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("location.reload();");

Two variations are worth remembering:

1. **location.reload()** performs a normal reload and may serve the page from cache.
2. **history.go(0)** is an older equivalent that some legacy suites still use.

The executor route runs inside the page, so it does not wait for the new document on its own. Follow it with an explicit wait exactly as you would after driver.navigate().refresh(), and remember that a script-driven reload will not clear a browser-level dialog. If the application under test loads its content asynchronously, the same care applies as when [handling AJAX calls in Selenium WebDriver](https://www.guru99.com/handling-ajax-call-selenium-webdriver.html).

## How to Avoid StaleElementReferenceException After a Refresh

A refresh destroys the current DOM and builds a new one. Every WebElement captured before the reload now points at a node that no longer exists, so the next call against it throws StaleElementReferenceException. This is the single most common failure that follows a page refresh.

Three habits remove almost all of these failures:

1. **Locate after, never before.** Store the By locator rather than the WebElement, and call findElement again once the reload has finished.
2. **Wait for a real signal.** An explicit wait on the visibility of an element that only exists after the reload is far more reliable than a fixed sleep.
3. **Refresh, then re-read.** Never carry a text value or an attribute captured before the reload into an assertion made after it.

The pattern below applies all three:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
driver.navigate().refresh();
WebElement search = wait.until(
        ExpectedConditions.visibilityOfElementLocated(By.id("username")));
search.sendKeys("guru99");

WebDriverWait takes a Duration in Selenium 4, which is a change from the integer-seconds constructor used in Selenium 3\. Wider techniques for these failures are covered in our guide to [exception handling in Selenium](https://www.guru99.com/exception-handling-selenium.html).

## Comparison of Selenium Page Refresh Methods

All six commands reload the page, but they differ in what they depend on and in how they fail.

| Method                                       | Depends on             | Reloads via                | When it is the right choice                             |
| -------------------------------------------- | ---------------------- | -------------------------- | ------------------------------------------------------- |
| driver.navigate().refresh()                  | Nothing extra          | The browser reload command | Almost always — the default                             |
| driver.get(driver.getCurrentUrl())           | A readable current URL | A fresh navigation         | When you also want to drop the history entry            |
| driver.navigate().to(driver.getCurrentUrl()) | A readable current URL | A fresh navigation         | Same as above, written through the Navigation interface |
| sendKeys(Keys.F5)                            | A focusable element    | A keystroke                | When you are deliberately testing the keyboard path     |
| sendKeys(“\\uE035”)                          | A focusable element    | A keystroke                | Identical to F5, written as a code point                |
| JavascriptExecutor location.reload()         | Scripting enabled      | A page script              | When the WebDriver command is blocked                   |

Start with the refresh command, and reach for another row only when it fails for a reason you understand. The same order of preference applies when you [maximize or resize the browser window](https://www.guru99.com/maximize-resize-minimize-browser-selenium.html): prefer the native WebDriver call and treat the script route as the fallback.

## FAQs

🔁 Does refreshing a page trigger the form resubmission dialog?

It can. If the current page was produced by a POST, the browser may ask to resend the data and the reload stalls behind that dialog. Navigating to the URL again with get() avoids the prompt entirely.

🐍 How do you refresh a page in Selenium with Python or C#?

The binding names differ but the command is the same: driver.refresh() in Python, driver.Navigate().Refresh() in C# and driver.navigate().refresh() in [Java](https://www.guru99.com/java-tutorial.html). All three issue the identical WebDriver instruction.

🍪 Does a page refresh clear cookies, session storage or local storage?

No. A reload keeps cookies, session storage and local storage for the same origin, which is why refresh is a poor way to reset state. Delete cookies explicitly or start a fresh browser session instead.

🤖 How does AI help with flaky tests caused by page reloads?

Self-healing engines re-resolve a locator from several attributes when the reloaded DOM no longer matches, and failure-analysis models cluster reload-timing flakes so the team fixes one wait rather than fifty tests.

🧠 Can GitHub Copilot generate Selenium page refresh code?

Yes, and the one-line refresh call is a suggestion it gets right consistently. The wait that has to follow it is where suggestions go wrong, so review any generated timeout against how the application actually loads.

♻️ Is there a hard refresh equivalent of Ctrl+F5 in Selenium?

There is no dedicated command. Teams approximate one by sending Ctrl and F5 together through the Actions class, or by disabling the cache through browser options, which is the more dependable route.

🖼️ Can Selenium refresh only an iframe instead of the whole page?

Not with the refresh command, which always reloads the top document. Switch into the frame and reload it with a script, or reset its source attribute, then switch back to the default content.

⏳ How long should a test wait for the page to finish reloading?

Do not guess with a fixed sleep. Use an explicit wait of ten to thirty seconds on a condition that is only true after the reload, so the test continues the moment the page is ready.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png","url":"https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png","width":"700","height":"250","caption":"Refresh Page using Selenium Webdriver","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/selenium-refresh-page.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/selenium","name":"Selenium"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/selenium-refresh-page.html","name":"Refresh Page using Selenium Webdriver"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/selenium-refresh-page.html#webpage","url":"https://www.guru99.com/selenium-refresh-page.html","name":"Refresh Page using Selenium Webdriver","dateModified":"2026-07-30T11:33:16+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/selenium-refresh-page.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta","url":"https://www.guru99.com/author/admin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","url":"https://www.guru99.com/images/krishna-rungta-v2-120x120.png","caption":"Krishna Rungta","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Selenium","headline":"Refresh Page using Selenium Webdriver","description":"During test automation of web-based application, there comes a need for the page to be refreshed multiple times for all web elements to be loaded completely. On the initial page load, some web element","keywords":"selenium","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/admin","name":"Krishna Rungta"},"dateModified":"2026-07-30T11:33:16+05:30","image":{"@id":"https://www.guru99.com/images/refresh-page-using-selenium-webdriver.png"},"copyrightYear":"2026","name":"Refresh Page using Selenium Webdriver","subjectOf":[{"@type":"HowTo","name":"How to Refresh Page in Selenium","description":"Here is a five ways to Refresh Page in Selenium.","step":[{"@type":"HowToStep","name":"Step 1) Driver.navigate.refresh command","text":"This is the inbuilt method for performing page refresh operation provided by Selenium web driver.","url":"https://www.guru99.com/selenium-refresh-page.html#step1"},{"@type":"HowToStep","name":"Step 2) Get method","text":"Get method can be used in a recursive way to refresh a page. In order to achieve this, we need to pass another method as an argument to the get method.","url":"https://www.guru99.com/selenium-refresh-page.html#step2"},{"@type":"HowToStep","name":"Step 3) Navigate method","text":"This method uses the same concept of recursion as mentioned above. getCurrentURL() method is passed as an argument to driver.navigate.to method.","url":"https://www.guru99.com/selenium-refresh-page.html#step3"},{"@type":"HowToStep","name":"Step 4) Send Keys method using F5 Key","text":"This is the second most commonly used method to refresh a page in Selenium. It takes the refresh key (F5 Key) as an argument to send keys method.","url":"https://www.guru99.com/selenium-refresh-page.html#step4"},{"@type":"HowToStep","name":"Step 5) Send Keys method using ASCII Code","text":"This method uses the same concept as above, but instead of passing the F5 key as an argument, we send the ASCII Code of refresh key as an argument. This can be accomplished as shown below.","url":"https://www.guru99.com/selenium-refresh-page.html#step5"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Does refreshing a page trigger the form resubmission dialog?","acceptedAnswer":{"@type":"Answer","text":"It can. If the current page was produced by a POST, the browser may ask to resend the data and the reload stalls behind that dialog. Navigating to the URL again with get() avoids the prompt entirely."}},{"@type":"Question","name":"How do you refresh a page in Selenium with Python or C#?","acceptedAnswer":{"@type":"Answer","text":"The binding names differ but the command is the same: driver.refresh() in Python, driver.Navigate().Refresh() in C# and driver.navigate().refresh() in Java. All three issue the identical WebDriver instruction."}},{"@type":"Question","name":"Does a page refresh clear cookies, session storage or local storage?","acceptedAnswer":{"@type":"Answer","text":"No. A reload keeps cookies, session storage and local storage for the same origin, which is why refresh is a poor way to reset state. Delete cookies explicitly or start a fresh browser session instead."}},{"@type":"Question","name":"How does AI help with flaky tests caused by page reloads?","acceptedAnswer":{"@type":"Answer","text":"Self-healing engines re-resolve a locator from several attributes when the reloaded DOM no longer matches, and failure-analysis models cluster reload-timing flakes so the team fixes one wait rather than fifty tests."}},{"@type":"Question","name":"Can GitHub Copilot generate Selenium page refresh code?","acceptedAnswer":{"@type":"Answer","text":"Yes, and the one-line refresh call is a suggestion it gets right consistently. The wait that has to follow it is where suggestions go wrong, so review any generated timeout against how the application actually loads."}},{"@type":"Question","name":"Is there a hard refresh equivalent of Ctrl+F5 in Selenium?","acceptedAnswer":{"@type":"Answer","text":"There is no dedicated command. Teams approximate one by sending Ctrl and F5 together through the Actions class, or by disabling the cache through browser options, which is the more dependable route."}},{"@type":"Question","name":"Can Selenium refresh only an iframe instead of the whole page?","acceptedAnswer":{"@type":"Answer","text":"Not with the refresh command, which always reloads the top document. Switch into the frame and reload it with a script, or reset its source attribute, then switch back to the default content."}},{"@type":"Question","name":"How long should a test wait for the page to finish reloading?","acceptedAnswer":{"@type":"Answer","text":"Do not guess with a fixed sleep. Use an explicit wait of ten to thirty seconds on a condition that is only true after the reload, so the test continues the moment the page is ready."}}]}],"@id":"https://www.guru99.com/selenium-refresh-page.html#schema-252495","isPartOf":{"@id":"https://www.guru99.com/selenium-refresh-page.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/selenium-refresh-page.html#webpage"}}]}
```
