Refresh the Current Page
To refresh the current web page using Selenium for Java, call navigate().refresh()
on the WebDriver object.
The following is a simple code snippet to refresh the current page.
</>
Copy
driver.navigate().refresh();
where
driver
is a WebDriver object.driver.navigate()
returns the Navigation object that allows functionalities like back, forward, refresh, etc.driver.navigate().refresh()
reloads the current web page and returns void.
Example
In the following program, we write Selenium Java code to visit Tutorialkart Home Page, and then reload/refresh the page.
Java Program
</>
Copy
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class MyAppTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
WebDriver driver = new ChromeDriver();
try {
driver.get("https://www.tutorialkart.com/");
//refresh the page
driver.navigate().refresh();
} finally {
driver.quit();
}
}
}