The Katalon Blog

How to refresh a page in Selenium WebDriver?

Written by Vincent N. | Oct 1, 2025 2:15:00 AM

Refreshing a page might seem simple. But when you're working with dynamic applications, forms, or session-sensitive flows, the way you refresh matters. A mis-timed reload can cause flaky results or unexpected behavior in your automation scripts.

That’s why knowing how to refresh the page in Selenium is essential. There are multiple ways to reload a page, and each has its own use case. Some simulate user behavior. Others trigger a full re-render of the DOM. Your choice affects both speed and test stability.

In this article, we’ll walk you through:

  • When and why to refresh a page during UI testing
  • Five different ways to refresh a page in Selenium WebDriver
  • How each method behaves under real-world test conditions
  • A comparison table to help you pick the right one

If you’ve ever asked, “What’s the best way to reload a page without breaking the test?”, you’ll find your answer here.

Let’s get started.

Scenarios when you need to refresh a page

There are many reasons you might want to refresh a page while using Selenium WebDriver. Each case comes from real user behavior and helps validate application stability.

  • Dynamic content validation: Some pages update regularly. Think stock tickers, live sports scores, or social feeds. You can refresh the page after a few seconds and assert the content changes. For example, a dashboard that shows live temperature data should reflect the latest values after reload.
  • Session timeout handling: Many websites have session timers. After a while, the user gets logged out. Refreshing the page can trigger that timeout behavior. In your test, you can wait for the timer, refresh, and confirm that the login prompt appears.
  • Form testing: Let’s say you fill in a shipping form, then reload the page. Some websites keep your data. Others clear it. You can test form persistence by entering test values, refreshing, and checking the input fields afterward. This is common in e-commerce or profile pages.
  • Error recovery: Sometimes, a page loads partially due to an AJAX failure. A manual refresh fixes it. Your test can simulate this by triggering the error state, then refreshing to ensure the app recovers. It works well with retry logic in test flows.
  •  Navigation testing: After reaching a page, you might refresh to ensure the URL and content still point to the same resource. This helps when working with filters or deep links. For example, in an airline search result page, refreshing should keep the search results visible.

Methods to refresh a page in Selenium WebDriver

Method 1: Using driver.navigate().refresh()

This is the most direct way to refresh a web page in Selenium. When you use driver.navigate().refresh(), Selenium simulates a browser refresh, just like when a user clicks the refresh button or presses F5.

It is fast, consistent, and fits perfectly in use cases where a standard reload is required. You can use this approach for AJAX retry testing, page stability checks, or refreshing after a login session timeout.

The method does not reload the page from the cache. Instead, it fully reloads the current document, making it suitable for dynamic sites.

The following code shows how to refresh the page in Selenium using navigate().refresh().

Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class RefreshExample {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://katalon.com");

    // Refresh the current page
    driver.navigate().refresh();

    driver.quit();
  }
}

Method 2: Using driver.get(driver.getCurrentUrl())

In Selenium, driver.get(driver.getCurrentUrl()) reloads the current page by navigating to the same URL again. It mimics typing the address into the browser bar and pressing enter.

This is slightly slower than navigate().refresh() but it guarantees a full page reload. You can use it when you want to clear session states or test how an application behaves after a complete page reload.

This method is especially helpful for verifying cache behavior or for reloading pages that load scripts dynamically.

Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HardRefreshExample {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://katalon.com");

    // Hard reload using the current URL
    String currentUrl = driver.getCurrentUrl();
    driver.get(currentUrl);

    driver.quit();
  }
}

Method 3: Using driver.navigate().to(driver.getCurrentUrl())

This approach uses the navigation API to move to the current URL again. It works just like driver.get() but supports history-based navigation, which fits well in end-to-end flows where the browser moves back and forth between pages.

In cases where your test jumps through multiple pages and then reloads the current one, this method feels more aligned with real user behavior. It also supports more advanced navigation strategies like chaining refresh with backward or forward steps.

If you're exploring how to refresh the page in Selenium for a journey-driven application, this method is a great choice.

Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class NavigationRefreshExample {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://katalon.com");

    // Reload using navigation API
    String currentUrl = driver.getCurrentUrl();
    driver.navigate().to(currentUrl);

    driver.quit();
  }
}

Method 4: Using JavaScript Executor (location.reload)

If you want more control over how you refresh the page, the JavaScript path gives you flexibility. It directly invokes the browser's native reload function, just like a developer would do in the browser console.

You can use this approach to trigger either a soft reload or a hard reload. By default, it performs a soft reload, which uses cache. You can add a true parameter to perform a full reload that bypasses cache and reloads from the server.

This is a really good method when you're testing dynamic components that rely heavily on AJAX calls like stock tickers or live feeds. You can trigger the refresh at exactly the right time and even chain it with other JavaScript-based validations.

Browser behavior might vary slightly depending on the app framework. It's a great technique when native reload methods don't fully update the DOM.

Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.JavascriptExecutor;

public class JavaScriptRefreshExample {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://katalon.com");

    // Refresh using JavaScript
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("location.reload()");

    driver.quit();
  }
}

Method 5: Using Keyboard Shortcuts (F5 / Ctrl+R)

This method is ideal when your goal is to simulate exactly what a user does in the browser. If you are testing keyboard-driven behavior or accessibility scenarios, this is a perfect fit. It sends real keystrokes to the browser window, like pressing F5 or Ctrl+R.

You can use the Actions class to send key inputs. On Windows or Linux, F5 and Ctrl+R work well. For macOS, you can simulate Command+R. Choose based on your platform to ensure consistency.

It fits well in UI-heavy applications where you want a full page refresh while preserving real-world interactions.

Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.Keys;

public class KeyboardRefreshExample {
  public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.get("https://katalon.com");

    // Refresh using keyboard F5
    Actions actions = new Actions(driver);
    actions.sendKeys(Keys.F5).perform();

    driver.quit();
  }
}

Comparison of Refresh Methods

Method How It Works Speed / Overhead Best For
driver.navigate().refresh() Simulates a browser refresh (like clicking the refresh button or pressing F5). Fast, low overhead. Standard reloads, AJAX retry, session timeout checks.
driver.get(driver.getCurrentUrl()) Navigates to the current URL again, forcing a full reload. Slightly slower than navigate().refresh(). Clearing session states, testing cache behavior.
driver.navigate().to(driver.getCurrentUrl()) Uses the navigation API to go to the same URL, fits well with history-based flows. Similar speed to driver.get(). Journey-driven apps, chaining refresh with back/forward steps.
JavaScript Executor (location.reload) Directly executes JS to reload the page, can perform soft or hard reload (true parameter bypasses cache). Flexible but depends on browser behavior. Dynamic components, AJAX-heavy pages, precise timing control.
Keyboard Shortcuts (F5 / Ctrl+R) Sends keystrokes to simulate user pressing F5 or Ctrl+R (Command+R on macOS).

Slowest, but most realistic.

Accessibility tests, simulating real user keyboard input.

Why choose Katalon to automate tests?

Katalon is a low-code automation platform built on top of Selenium. It brings a modern interface and powerful built-in capabilities that remove the complexity of traditional test scripts, making test automation more accessible to teams of all skill levels.

With Katalon, you get:

  • All-in-One Platform: Design, execute, manage, and report on your tests in one place. Focus on building quality tests instead of stitching together multiple tools.
  • Cross-Browser & Cross-Platform Execution: Run tests on thousands of browser and OS combinations out of the box, no manual driver setup required.
  • Seamless CI/CD Integration: Integrate easily with your pipelines and cloud environments to run tests in parallel and shorten feedback loops.
  • AI-Powered Self-Healing Locators: Make your tests more resilient as Katalon adapts automatically when your application UI changes.
  • Rich Dashboards & Reports: Track coverage, performance, and quality over time with detailed analytics built in.

In short, Katalon supercharges Selenium. It gives you the power of test automation in a scalable, team-friendly package that grows with your projects.

📝 Want to explore what Katalon can do for your team? Request a demo to see how it helps teams automate faster with less effort.