推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
oooolongtea
V2EX  ›  Python

Selenium Chrome driver 该如何清除缓存然后刷新页面?

  •  
  •   oooolongtea · Apr 9, 2020 · 5981 views
    This topic created in 2409 days ago, the information mentioned may be changed or developed.
    大家好,
    我目前用 Selenium Webdriver 写了一个框架来测试我们公司产品的页面相应速度。
    具体的工作流程就是这个框架会手动点击网页图标,然后去测试打开这个页面的速度(我们选取并且等待页面上一个元素的显示或者消失的时间作为这个页面的读取速度)。

    因为要测试不同的页面,每次我们在结束测试一个页面后,希望能清除一下缓存,然后再去测试下一个页面( chrome 里有类似的功能,叫做“清空缓存并刷新”)。因为缓存会影响下一个页面的读取速度。

    请问在 Selenium 里有实现该功能的办法吗?
    6 replies  •  2020-04-10 14:06:17 +08:00
    cmlanche
    cmlanche
    Apr 9, 2020
    1
    不是有 driver.getSessionStorage().clear() 清空缓存吗
    cmlanche
    cmlanche
    Apr 9, 2020
    2
    driver.getLocalStorage().clear()
    oooolongtea
    oooolongtea
    OP
    Apr 9, 2020
    3
    @cmlanche 我运行这个,然后再刷新页面,效果会和 chrome 里面的“清空缓存并刷新”一样吗?
    cmlanche
    cmlanche
    Apr 9, 2020
    4
    是的啊
    oooolongtea
    oooolongtea
    OP
    Apr 9, 2020
    5
    @cmlanche ok 我去研究研究看看。 多谢!
    jeeyong
    jeeyong
    Apr 10, 2020
    6
    driver.delete_all_cookies()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2051 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 14:51 · PVG 22:51 · LAX 06:51 · JFK 09:51
    ♥ Do have faith in what you're doing.