Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hard refresh using Selenium

We have various ways in Selenium like driver.navigate().refresh(); and driver.execute_script("location.reload()") to do refresh, but these perform normal refresh. I want to hard refresh my page, is there any way to hard refresh the page using Selenium.
The code in any of Java/Python would be welcomed.

Note: I don't want to use Robot class to perform it, so please provide any other way to do it.

like image 404
Sameer Arora Avatar asked Feb 07 '19 10:02

Sameer Arora


People also ask

How many ways we can refresh browser in Selenium?

4 Ways to Refresh Page In Selenium Webdriver.

How can I tell if Selenium is refreshing?

UPDATE: Page refresh can also easily be verified if there is some textbox element present. Simply use type command to insert some text into the textbox field, then refresh the page, and the text inside textbox should return to it's original state.

Which of the following in Selenium is used to refresh browser window Javascript?

navigate(). refresh(); In order to see how exactly we can make use of refresh driver method to refresh a web page in selenium javascript let's see the following automation scenario.

How do I refresh my browser?

While holding, press refresh ⟳. Using Chrome on mobile, go to ⋮ (Android) or … (iOS) > Settings > Privacy > Clear Browsing Data > Clear Browsing Data (iOS) or Clear Data (Android).


Video Answer


1 Answers

A Regular refresh may reload the page from its cache.

A Hard refresh reloads from the server, not from cache.


If you wish to delete the Cache too use Cache.delete():

see MDN Web Docs on Cache.delete().


The answer:

You can use location.reload(true); with execute_script:

driver.execute_script("location.reload(true);")

Reloads the resource from the current URL. Its optional unique parameter is a Boolean, which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.

For more info see MDN Web Docs on Location.

Hope this helps!

like image 102
Moshe Slavin Avatar answered Oct 21 '22 00:10

Moshe Slavin