如何设置文档。
我正在努力通过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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论