javascript - 如何使用 Selenium 进行硬刷新

标签 javascript java python selenium selenium-webdriver

我们在 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/

相关文章:

java - 使用鼠标运动监听器绘制线条

python - 使用 pandas 绘制 Bokeh 线图的问题

php - 提供 JSONP 是否安全?

javascript - 工厂内的$watch

java - 将 JavaRDD<Tuple2<Object, long[]>> 转换为 Java 中的 Spark Dataset<Row>

java - 为什么递归 MergeSort 比迭代 MergeSort 更快?

Python 多处理实现简单计数器的简便方法?

python - 如何在单个类的每个实例上使用方法?

javascript - Reactjs : Invariant Violation when using input element

javascript - 刷新 Angular UI Grid 后所选项目未重置