如何设置文档。

发布于 2025-01-25 06:02:40 字数 665 浏览 1 评论 0原文

我正在努力通过Selenium设置“ Document.Cookie”值。我想取得这样的目标。通常,当我在像Chrome这样的真正浏览器上时,我打开控制台和类型

document.cookie='my_secret_cookie=1;path=/'

,一切都像魅力一样工作。

如何通过硒实现这一目标?目前,我已经做过这样的事情,但似乎对我不起作用:

Date today    = new Date();
Date tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24));
Cookie newCookie = new Cookie.Builder("myCookie","my_secret_cookie=1")
                .domain("my.site") // declared in my local.properties file
                .path("/")
                .expiresOn(tomorrow) 
                .isSecure(true) 
                .build(); 

driver.manage().addCookie(newCookie);

有什么建议吗?

I'm struggling with setting "document.cookie" value via Selenium. I want to achieve something like this. Generally, when I'm on a real browser like Chrome, I open the console and type

document.cookie='my_secret_cookie=1;path=/'

And everything works like a charm.

How can I achieve this via Selenium? Currently, I've done something like this, but it doesn't seem to work for me:

Date today    = new Date();
Date tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24));
Cookie newCookie = new Cookie.Builder("myCookie","my_secret_cookie=1")
                .domain("my.site") // declared in my local.properties file
                .path("/")
                .expiresOn(tomorrow) 
                .isSecure(true) 
                .build(); 

driver.manage().addCookie(newCookie);

Any advice?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文