Refreshing Page In Different Ways Using Webdriver

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

  1. using navigate( ).refresh( )
  2. using getCurrentUrl( )
  3. 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();
}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.