通过 Selenium/PHPunit 访问浏览器会话文件或缓存
我正在尝试通过 Selenium 从网站下载图片。到目前为止,我发现的示例建议通过 selenium 检索图片 URL,然后使用 HTTP 库(例如 cURL)下载图片。
由于在运行 Selenium 测试时首先已经下载了图片,因此我发现对每张图片发出另一个单独的请求并不是一个好主意。
有没有办法可以通过 Selenium/PHPunit 从浏览器缓存中获取图片(或者如果 selenium 服务器将它们本地存储在临时会话文件夹中,则可以在本地获取图片)?
谢谢。
I am trying to download pictures from a site through Selenium. Examples I found so far advised to retrieve the pictures URL via selenium, then download the picture with an HTTP library such as cURL.
Since the pictures are already downloaded in the first place when running the Selenium test I found making another separate request for each picture not to be a good idea.
Is there a way I can get the pictures from the browser cache via Selenium/PHPunit (or maybe locally if the selenium server stored them locally in a temporary session folder)?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个老问题,但由于我最近一直在使用 Selenium,我想我应该把这个问题放在这里,供任何偶然发现这个问题的人参考。
在我对 Selenium 的阅读和实践中,这里的问题是浏览器缓存不是由 Selenium 直接处理的,因此访问缓存的代码必须基于每个浏览器,并且很可能很脆弱。
使用 CURL 方法可以保证获得所需的图像。
如果 Selenium 确实允许访问文件的缓存版本,那就太好了,就像它可以截屏一样(截屏就足够了吗?)
您可以在 PHPUnit 中执行此操作,如下所示:
希望这会有所帮助!
Its an old question, but since I've been working with Selenium recently, I figured I'd put this here for anyone that stumbles on this.
In my readings on Selenium and in practice, the issue here is that the browser cache is not handled directly by Selenium, so the code to access the cache would have to be on a per-browser basis, and very likely to be brittle.
Using the CURL method would guarantee getting the images needed.
It would be great if Selenium did allow access to the cached versions of files, just as it can take screenshots (would a screenshot suffice?)
You can do that in PHPUnit like so:
Hope this helps!