slimerjs
slimerjs copied to clipboard
Using Python Selenium: add_cookie(..) from request-host sub.foo.bar for domain=.foo.bar should be accepted
versions
- SlimerJS: 0.10.3
- Firefox: 52.0.2 32bit
- Operating system: Win10 64bit
- IPython 5.1.0 (Python 2.7.11 |Anaconda 2.4.1 (64-bit))
- selenium-3.3.3
Steps to reproduce the issue
Two approaches which both work with PhantomJS but yield different results in SlimerJS.
- First (failing) approach is using standard
driver.add_cookie(..)
- Second (working) approach using
executePhantomScript > phantom.addCookie
(and yes, this was tested with existing domains in the first place, but sub.foo.bar
works fine for reproduction)
Fails
In [10]: driver = webdriver.PhantomJS(executable_path=r"C:/dev/slimerjs-0.10.3/slimerjs.bat")
In [11]: driver.get('http://sub.foo.bar')
In [12]: driver.get_cookies()
Out[12]: []
In [13]: driver.add_cookie({'domain':'.foo.bar','name':'foo', 'value':'bar'})
In [14]: driver.get_cookies()
Out[14]:
[{u'domain': u'sub.foo.bar',
u'expires': None,
u'expiry': None,
u'httponly': False,
u'name': u'foo',
u'path': u'/',
u'secure': False,
u'value': u'bar'}]
Works
In [18]: driver.get('http://sub.foo.bar')
In [19]: driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
In [20]: driver.execute('executePhantomScript',
...: {'script': '''
...: phantom.addCookie({
...: name : 'foo',
...: value : 'bar',
...: domain : '.foo.bar'
...: });
...: ''', 'args': []})
Out[20]:
{u'sessionId': u'99c9a410-202f-11e7-8819-db721ac5423e',
u'status': 0,
u'value': {}}
In [21]: driver.get_cookies()
Out[21]:
[{u'domain': u'.foo.bar',
u'expires': None,
u'expiry': None,
u'httponly': False,
u'name': u'foo',
u'path': u'/',
u'secure': False,
u'value': u'bar'}]
Actual results:
driver.add_cookie({'domain':'.foo.bar','name':'foo', 'value':'bar'})
adds cookie to sub.foo.bar
instead of .foo.bar
.
The result is independent using a trailing dot or not:
-
domain : '.foo.bar'
or -
domain : 'foo.bar'
Expected results:
Cookie domain should be accepted for a private top-level domain, when added at sub-domain level.
As in the approach using executePhantomScript > phantom.addCookie
.
I don't understand anything. I can do anything with your example, as I don't know Selenium. Please check first that the issue exists without Selenium.
Thx @laurentj, I try to isolate this issues, too.
Have you found a solution? Looks like that domain
and path
are ignored by add_cookie
method.