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.
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.
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.
I get Compiler Error CS0201:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement