我们在 Selenium 中有多种方法,例如 driver.navigate().refresh();
和 driver.execute_script("location.reload()")
来进行刷新,但这些执行正常刷新。我想硬刷新我的页面,有什么方法可以使用 Selenium 来硬刷新页面。
欢迎任何 Java/Python 中的代码。
注意:我不想使用 Robot 类来执行它,所以请提供任何其他方法来执行它。
最佳答案
常规刷新可能会从缓存中重新加载页面。
硬刷新从服务器重新加载,而不是从缓存。
如果您也想删除缓存,请使用 Cache.delete()
:
参见 MDN Web Docs on Cache.delete() .
答案:
您可以将 location.reload(true);
与 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.
有关详细信息,请参阅 MDN Web Docs on Location .
希望这对您有所帮助!
关于javascript - 如何使用 Selenium 进行硬刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54571696/