refresh a webpage in selenium

Refresh a Webpage in Selenium

Last updated on

There are multiple ways to refresh a webpage in Selenium Webdriver. In this post, we will present all these ways and also specify which one is the best.

refresh in selenium

1. Using driver.navigate() command
Selenium Webdriver provides inherent support for refreshing a webpage using its driver.navigate() command. This is by far the most preferred and widely used way of refreshing a webpage.

driver.navigate().refresh();


2. Opening current URL using driver.getCurrentUrl() with driver.get() command

driver.get(driver.getCurrentUrl());


3. Opening current URL using driver.getCurrentUrl() with driver.navigate() command

driver.navigate().to(driver.getCurrentUrl());


4. Pressing F5 key on any textbox using sendKeys command

driver.findElement(By textboxLocator).sendKeys(Keys.F5);


5. Passing ascii value of F5 key i.e. “\uE035” using sendKeys command

driver.findElement(By textboxLocator).sendKeys("\uE035");


That’s all we have in this post, comment below if you have any queries. Also please share this post with your friends and don’t forget to check our complete selenium tutorial here.

Selenium Webdriver Tutorial

2 thoughts on “Refresh a Webpage in Selenium”

  1. I do not want to refresh the page. How or can I refresh just the DOM content? In Telerik you can refresh the DOM content without refreshing the page. I was wondering if Selenium had something similar? Thanks for any help you can give.

    Reply
  2. I get Compiler Error CS0201:
    Only assignment, call, increment, decrement, and new object expressions can be used as a statement

    Reply

Leave a Comment