Refresh Page using Selenium Webdriver

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 elements might be loaded while it takes a second page refresh for all web elements to be loaded. This can be done using the refresh command provided by Selenium web driver.

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. command

1) Driver.navigate.refresh command

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


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


Test Scenario:

  1. Open firefox browser with web page –
  2. Once the page is loaded successfully, refresh the web page using driver.navigate.refresh method
  3. Close the browser using driver.close() method


package Guru99Demo;
import org.openqa.selenium.WebDriver;
public class RefreshDemo {
public static void main(String args[]) throws InterruptedException
System.setProperty("", "D: \\chromedriver.exe");
WebDriver driver = new ChromeDriver();

Code Output:

Initial page load

Driver Navigate Refresh Command

After page refresh operation… the video has changed

Driver Navigate Refresh Command

Multiple other ways to refresh a page

2) Get method

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.



3) Navigate method:

This method uses the same concept of recursion as mentioned above. getCurrentURL() method is passed as an argument to method.



4) Send Keys method using F5 Key:

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. Since send keys works only on web elements rather than the browser, we must initially identify a valid web element on the web page and then use the send keys method. This can be accomplished as shown below.


driver. findElement("username")).sendKeys(Keys.F5);

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 ASCII Code of refresh key as an argument. This can be accomplished as shown below.

driver. findElement("username")).sendKeys(“\uE035”);


  • Page refresh operation ensures that all the web elements of a page are loaded completely before we proceed with our test cases automation
  • Most commonly used method for page refresh in Selenium is the driver.navigate().refresh() method
  • Get method and navigate methods include the recursive ways to refresh a page in Selenium
  • Send Keys method can be used to refresh a page either by passing F5 key as an argument or its corresponding ASCII Code