V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2020-04-09 06:42:58 +08:00 · 5251 次点击
    这是一个创建于 1478 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大家好,
    我目前用 Selenium Webdriver 写了一个框架来测试我们公司产品的页面相应速度。
    具体的工作流程就是这个框架会手动点击网页图标,然后去测试打开这个页面的速度(我们选取并且等待页面上一个元素的显示或者消失的时间作为这个页面的读取速度)。

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

    请问在 Selenium 里有实现该功能的办法吗?
    6 条回复    2020-04-10 14:06:17 +08:00
    cmlanche
        1
    cmlanche  
       2020-04-09 09:06:01 +08:00
    不是有 driver.getSessionStorage().clear() 清空缓存吗
    cmlanche
        2
    cmlanche  
       2020-04-09 09:06:58 +08:00
    driver.getLocalStorage().clear()
    oooolongtea
        3
    oooolongtea  
    OP
       2020-04-09 10:17:44 +08:00
    @cmlanche 我运行这个,然后再刷新页面,效果会和 chrome 里面的“清空缓存并刷新”一样吗?
    cmlanche
        4
    cmlanche  
       2020-04-09 10:21:42 +08:00
    是的啊
    oooolongtea
        5
    oooolongtea  
    OP
       2020-04-09 10:29:51 +08:00
    @cmlanche ok 我去研究研究看看。 多谢!
    jeeyong
        6
    jeeyong  
       2020-04-10 14:06:17 +08:00
    driver.delete_all_cookies()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1696 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:04 · PVG 01:04 · LAX 10:04 · JFK 13:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.