即使我处于正确的域名,Selenium addCookie也会获取无效的Cookie域例外 [英] Selenium addCookie getting Invalid Cookie Domain Exception even though I'm on the right domain

查看:3078
本文介绍了即使我处于正确的域名,Selenium addCookie也会获取无效的Cookie域例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图将先前保存的cookie加载到我的网络驱动程序中,使用Selenium / Geb。首先,我转到域名,然后尝试添加cookie。但cookie域和url域不会相互注册:

 被捕获:org.openqa.selenium.InvalidCookieDomainException: 
您只能添加对当前网域可见的Cookie:.domain = .example.com => .www.example.com
Build info:version:'2.35.0',revision:'8df0c6bedf70ff9f22c647788f9fe9c8d22210e2',time:'2013-0 8-17 12:46:41'
系统信息:os .name:'Linux',os.arch:'amd64',os.version:'3.2.0-48-generic',java.version:'1.6.0_27'
驱动程序信息:driver.version:unknown

看起来cookie的域名是 .example.com http://example.com .www.example.com 。我能想到的唯一解决方案是重写某种方法来欺骗我当前的域名,但我不知道如何去做。

解决方案

我有一个类似的问题,当我得到您只能为当前域设置Cookie明显的原因。



我通过剥离除名称和值之外的所有参数的cookie来解决它:

(Python)

  cookies = pickle.load(打开(cookies.pkl,rb))
用于cookie中的cookie :
打印cookie
new_cookie = {}
new_cookie ['name'] = cookie ['name']
new_cookie ['value'] = cookie ['value']
driver.add_cookie(new_cookie)


So I'm trying to load previously saved cookies into my web driver with Selenium/Geb. First I goto the domain and then try to add the cookies. But the cookie domain and the url domain don't register with each other:

Caught: org.openqa.selenium.InvalidCookieDomainException: 
You may only add cookies that would be visible to the current domain: .domain=.example.com => .www.example.com
Build info: version: '2.35.0', revision: '8df0c6bedf70ff9f22c647788f9fe9c8d22210e2', time: '2013-0  8-17 12:46:41'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-48-generic', java.version:   '1.6.0_27'
Driver info: driver.version: unknown

It seems the cookie's domain is .example.com and the domain I get to when I go to http://example.com is .www.example.com. The only solution I can think of is overriding some method to spoof my current domain, but I have no idea how to go about that.

解决方案

I had a somewhat similar problem where I was getting the "You may only set cookies for the current domain" error for no apparent reason.

I solved it by striping the cookie of all the parameters except name and value:

(Python)

cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    print cookie
    new_cookie={}
    new_cookie['name']=cookie['name']
    new_cookie['value']=cookie['value']
    driver.add_cookie(new_cookie)

这篇关于即使我处于正确的域名,Selenium addCookie也会获取无效的Cookie域例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆