Closed
Description
Meta -
OS: Ubuntu 17.04
Selenium Version: 3.5.1
Browser: FireFox
Browser Version: 55.0.3
Expected Behavior -
- Loaded the webpage http://www.cbc.ca
- Add a cookie with the domain .www.cbc.ca
- Cookie is added
Actual Behavior -
- Loaded the webpage http://www.cbc.ca
- Add a cookie with the domain .www.cbc.ca
- Exception is generated due to the dot (.) in front of the www.cbc.ca
amplitude_id_statswww.cbc.ca=eyJkZXZpY2VJZCI6IjMzZjA1NzU4LTc3ODMtNDBmOS05NDZkLWIyOWNhYzA0YTMyZVIiLCJ1c2VySWQiOm51bGwsIm9wdE91dCI6ZmFsc2UsInNlc3Npb25JZCI6MTUwNzgzNzAxMTU5OCwibGFzdEV2ZW50VGltZSI6MTUwNzgzNzAxMTYwMCwiZXZlbnRJZCI6MSwiaWRlbnRpZnlJZCI6MCwic2VxdWVuY2VOdW1iZXIiOjF9; path=/; **domain=.www.cbc.ca**
You may only set cookies for the current domain
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.10.0-35-generic', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.Hp4phd3YgXqn, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=55.0.3, platformVersion=4.10.0-35-generic, moz:processID=9650.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
Session ID: c720ed38-7226-458f-8a77-aed7336a1c37
org.openqa.selenium.InvalidCookieDomainException: You may only set cookies for the current domain
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.10.0-35-generic', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=/tmp/rust_mozprofile.Hp4phd3YgXqn, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=55.0.3, platformVersion=4.10.0-35-generic, moz:processID=9650.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
Session ID: c720ed38-7226-458f-8a77-aed7336a1c37
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions.addCookie(RemoteWebDriver.java:768)
Steps to reproduce -
driver.get(cbcURL);
driver.manage().addCookie(cbcCookie);
Activity
p0deje commentedon Oct 16, 2017
.cbc.ca
work?.www.cbc.ua
.p0deje commentedon Oct 16, 2017
Actually, WebDriver spec defines the add cookie logic:
So the behavior is defined. If you think it's incorrect one, please raise an issue for specification. Once the specification is changed, drivers will adopt the new behavior.
P.S. I also checked that you can add cookie with
.cbc.ca
domain and I believe that's what you actually want to achieve (i.e. adding cookies available to subdomains).alexgmuir commentedon Oct 16, 2017
Be5yond commentedon Nov 9, 2017
@p0deje, hello, I got exactly the same problem. here is some log for what happened in my case.
any request access shop.mysite.com without access_token would be redirect to login.mysite.com.
after I hit my login button. I paused the script. PS: I am using the pytest so selenium is a webdriver instance.
(Pdb) selenium.get_cookies()
[{'name': 'access_token', 'value': '23a3ec47-9feb-4898-90f0-3a540d6041c9', 'secure': False, 'httpOnly': False, 'path': '/', 'expiry': 1512812800, 'domain': '.mysite.com'}]
(Pdb) cookie = selenium.get_cookies()[0]
(Pdb) selenium.delete_all_cookies()
(Pdb) selenium.add_cookie(cookie)
(Pdb) selenium.get_cookies()
[{'name': 'access_token', 'value': '23a3ec47-9feb-4898-90f0-3a540d6041c9', 'secure': False, 'httpOnly': False, 'path': '/', 'expiry': 1512812800, 'domain': 'shop.mysite.com'}]
any help would be appreciated.
OS: Ubuntu 17.04
Selenium Version: 3.7.0
dbstraffin commentedon Feb 16, 2018
I have ths same issue (I can read a cookie but not set that same cookie via Selenium). It's easy to workaround using javascript.
Here is an example using python: