How to refresh browser in Selenium WebDriver using different methods

In this article, we will talk about how can we refresh browser using various methods.

Some time it is required to refresh the webpage to accomplish the testing objective. Let us see how this can be achieved.

Method1: Using navigate().refresh() method

Method2: Using JavaScriptExecutor

Method3: Using Actions Class

Mehtod4: Get the current URL & navigate using get() method

Method5: Get the current URL & navigate using navigate().to() method

Look at the below example –
package basicsOfSelenium;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class RefreshBrowserInDiffWays {

 public static void main(String[] args) {

  WebDriver driver = new FirefoxDriver();
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  // Method1:  Using navigate().refresh() method
  //Method2: Using JavaScriptExecutor
  JavascriptExecutor js = (JavascriptExecutor)driver;
  //Method3: Using Actions Class
  Actions actions = new Actions(driver);
  //Mehtod4: Get the current URL & navigate using get() method
  //Method5: Get the current URL & navigate using navigate().to() method


Hope this helps!!!!

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

Get the Framework code at Github Repo: