如何使用硒硬刷新 [英] How to hard refresh using Selenium

查看:66
本文介绍了如何使用硒硬刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Selenium中有多种方式,例如driver.navigate().refresh();driver.execute_script("location.reload()")来进行刷新,但是它们执行常规的刷新.我想硬刷新页面,有什么方法可以使用Selenium硬刷新页面.
欢迎使用Java/Python中的任何代码.

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.

注意:我不想使用Robot类来执行它,所以请提供其他方法来实现它.

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

推荐答案

常规刷新可能会从其缓存中重新加载页面.

A Regular refresh may reload the page from its cache.

刷新是从服务器而不是从缓存重新加载.

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

如果您也想删除缓存,请使用Cache.delete():

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

请参见Cache.delete()上的 MDN Web文档.

see MDN Web Docs on Cache.delete().

您可以将location.reload(true);execute_script一起使用:

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

从当前URL重新加载资源.它的可选唯一参数是布尔值,当它为true时,它将导致始终从服务器重新加载页面.如果为false或未指定,浏览器可能会从其缓存中重新加载页面.

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文档.

For more info see MDN Web Docs on Location.

希望这会有所帮助!

这篇关于如何使用硒硬刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆