How to Refresh a Page with Selenium and C#
Refresh the current page in Selenium with C# using `driver.Navigate().Refresh()`. Learn when to wait, how to verify the result, and how to handle common issues.
To refresh the current page in Selenium with C#, call driver.Navigate().Refresh() on an initialized IWebDriver:
driver.Navigate().Refresh();
The command initiates a reload. If the next test step depends on the page being ready, wait for the specific title, element, or state your test needs instead of assuming the refresh call alone proves readiness.
Minimal runnable example
This console example uses Selenium’s .NET WebDriver package and ChromeDriver. Install the Selenium.WebDriver NuGet package and make Chrome available to the driver setup in your environment.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://selenium.dev");
driver.Navigate().Refresh();
Console.WriteLine($"Page title after refresh: {driver.Title}");
The title read is an example of checking an observable result. In a real test, assert the title or application state that matters. The official Selenium C# navigation example also refreshes with driver.Navigate().Refresh() and then checks the title. See Selenium browser navigation documentation.
Step-by-step: refresh and verify
- Start a driver and load the page. The driver must already be initialized and on the page you intend to reload.
- Refresh through the navigation interface. Call
driver.Navigate().Refresh(). - Wait for the condition your next action needs. For example, wait for a particular element to appear or for text to reach an expected value.
- Assert the outcome. Verify a stable, relevant page state. A reload does not guarantee that dynamic data changes.
IWebDriver is Selenium’s main interface for controlling a browser. Its Navigate() method provides access to navigation operations. See the official .NET IWebDriver API reference.
Wait for the state you need
A browser reload can return control before every asynchronous application update relevant to your test has completed. Use an explicit wait for a meaningful condition rather than an arbitrary delay. For example, this waits for an element to become visible:
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
// Assume driver is initialized and the page is loaded.
driver.Navigate().Refresh();
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
var status = wait.Until(d =>
{
var element = d.FindElement(By.Id("status"));
return element.Displayed ? element : null;
});
Console.WriteLine(status.Text);
This example requires Selenium’s support classes, provided by the Selenium.Support NuGet package. Replace status with a condition that represents readiness for your application: expected text, a changed attribute, a loaded result row, or another observable state. Keep the wait bounded so a failure produces a useful timeout rather than hanging indefinitely.
Refresh behavior and alternatives
| Approach | When to use it | Notes |
|---|---|---|
driver.Navigate().Refresh() |
Reload the current page in a normal WebDriver test. | The general-purpose C# navigation call shown in Selenium’s official example. |
RefreshAsync() |
Only when using a wrapper that exposes this API, such as the relevant Selenium EventFiringWebDriver implementation. |
It is not a universal IWebDriver method. Check the concrete driver or wrapper API before using it. |
Do not assume refresh bypasses browser or intermediary caches, or that it makes server-side or client-side data different. The cited Selenium API material does not establish either guarantee. Test the observable behavior your application requires.
Common problems and fixes
| Symptom | Likely cause | What to do |
|---|---|---|
| The next lookup fails immediately after refresh. | The application has not reached the state needed by the next step, or the old element reference is stale after navigation. | Wait for a relevant condition, then locate the element again after the refresh. |
| The wait times out. | The condition never became true, the locator is incorrect, or the page failed to load as expected. | Check the locator and expected state, inspect the page and browser logs, and use a timeout appropriate to the application. |
| The title or displayed data is unchanged. | A reload does not guarantee changed content; the server or app may return the same state. | Assert the state required by the test, and arrange test data or application behavior so that state is deterministic. |
RefreshAsync() is unavailable. |
The active driver type or wrapper does not provide that method. | Use driver.Navigate().Refresh(), or consult the API for the exact wrapper in use. |
| The browser does not start. | The driver, browser, or local environment is not configured correctly. | Confirm the browser is installed and that your Selenium driver setup can locate or manage the matching browser driver. |
Reliability and performance notes
- Wait on application state. A fixed sleep adds delay to every successful run and can still be too short on a slow run. A condition-based wait proceeds as soon as the required state appears and fails with a bounded timeout otherwise.
- Keep assertions deterministic. A refresh is a navigation action, not a guarantee that content changes. Use controlled data and assert a specific outcome.
- Account for navigation cost. Refreshing reloads the page and can repeat network and application work. Avoid unnecessary refreshes in a test path.
- Make failures diagnosable. On timeout, capture relevant logs or page state and report which expected condition was not met.
Or skip the browser setup
If you need a screenshot of a URL rather than a browser automation test, ScreenshotNeo returns an image or PDF with one GET request. Its API accepts screenshot options for full-page or element capture, viewport and device settings, waits, custom CSS or JavaScript, headers and cookies, and more. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. Its MCP server gives Claude, Cursor, and other MCP clients tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
FAQ
What is the Selenium C# refresh command?
Use driver.Navigate().Refresh() on an initialized WebDriver.
Does refresh guarantee new data?
No. It reloads the page, but the application may show the same content. Verify the state your test actually requires.
Can I use RefreshAsync()?
Only if the specific driver wrapper you are using exposes it. Selenium’s support source includes it on EventFiringWebDriver; it is not a general method on every WebDriver type.


