Selenium gives the flexibility to refresh a page in different ways. You get the navigate( )method to navigate within, from and to a webpage.
Also you can use the getCurrentUrl( ) method to get the current page url and then use it to refresh the page. Also you can use the key stroke combination to refresh the page. We will use different combinations of these following methods to refresh the page
- using
navigate( ).refresh( ) - using
getCurrentUrl( ) - using
sendKeys( )
private WebDriver driver;
private String baseUrl;
@Test
public void testmain() {
driver.get(baseUrl);
//first type
driver.navigate().refresh();
//second type
driver.findElement(By.name("s")).sendKeys(Keys.F5);
//third type
driver.get(driver.getCurrentUrl());
//fourth type
driver.navigate().to(driver.getCurrentUrl());
//fifth type
driver.findElement(By.name("s")).sendKeys("\uE035");
}
@BeforeTest
public void setup() {
driver= new FirefoxDriver();
baseUrl="http://www.toolsqa.com/";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterTest
public void teardown() {
driver.quit();
}
}