Header Ads

What is the defference between driver.navigate().refresh() and pressing F5?

I was going through a forum and found one of my mate tried to refresh a page after doing some operation in web. He used..
driver.findElement(By.xpath("//body")).sendKeys(Keys.F5);


But this code was failing while running the code. I was googling for a suggestion or help and finally found one solution in stackoverflow..

Being interested , I observed all the possible causes and agreed the discussion there. The summary I found is as below:
It's not exactly equivalent to pressing F5 though. driver.navigate().refresh() in its request header says "no-cache" and, as a result, unconditionally reloads all content. Whereas pressing F5 could result in a "If-Modified-Since" request, that could get a "304 Not Modified" response.
Wow that is what I was looking for. Since this page is based on ajax so F5 was not working there. When I have used
driver.navigate().refresh();


It worked like a boom.
Also for pressing F5, we have one more option..

Actions actionObject = new Actions(driver);
actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();


Hope that helps.
Powered by Blogger.