如何使用 Selenium RC 保存和恢复所有 cookie?

发布于 2024-09-10 19:19:17 字数 186 浏览 2 评论 0原文

我正在运行复杂的测试,为网站的不同部分创建许多 cookie。

有时,我必须在长时间测试中重新启动浏览器,并且由于 Selenium 服务器不会修改基本 Firefox 配置文件,因此 cookie 会消失。

有什么方法可以在终止浏览器之前将所有 cookie 保存到 Python 变量中,并在启动新的浏览器实例后恢复它们?

I'm running complex tests that create many cookies for different sections of my web site.

Occasionally I have to restart the browser in the middle a long test and since the Selenium server doesn't modify the base Firefox profile, the cookies evaporate.

Is there any way I can save all of the cookies to a Python variable before terminating the browser and restore them after starting a new browser instance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£烟消云散 2024-09-17 19:19:17

是的,当然。查看 getCookiegetCookieByNamecreateCookie 方法。

Yes, sure. Look at getCookie, getCookieByName and createCookie methods.

蓝眼泪 2024-09-17 19:19:17

我认为您应该创建一个浏览器配置文件并为该配置文件启动服务器。因此,您的所有 cookie 在每次执行期间都会被保存/修改。我已将这些详细信息作为另一个问题的答案。请参考。。它是为 java 客户端和 firefox 提供的,但我确信您可以根据您的要求实现它。

I think you should crate a browser profile and start server for that profile. So all your cookies get saved/modified during every execution. I've gievn these details as answer for another question . Please refer it.. It is given for java client and firefox but I'm sure you can implement it as per your requirements.

つ低調成傷 2024-09-17 19:19:17

我认为应该可以使用 Chrome-developer-protocoll getCookies< /a> 方法。

使用 Python,您可以按如下方式执行它:

cookies = driver.execute_cdp_cmd("Network.getCookies", {})

应该返回:

name
value
domain
path
expires
size
httpOnly
secure
...

和其他一些(请参阅 Network.Cookie 类型对象)

I think it should be possible using the Chrome-developer-protocoll getCookies method.

Using Python, you would execute it as following:

cookies = driver.execute_cdp_cmd("Network.getCookies", {})

Which should return:

name
value
domain
path
expires
size
httpOnly
secure
...

and some others (see Network.Cookie Type-Object)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文