slimerjs icon indicating copy to clipboard operation
slimerjs copied to clipboard

Using Python Selenium: add_cookie(..) from request-host sub.foo.bar for domain=.foo.bar should be accepted

Open spex66 opened this issue 7 years ago • 3 comments

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.

spex66 avatar Apr 13 '17 10:04 spex66

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.

laurentj avatar Apr 21 '17 12:04 laurentj

Thx @laurentj, I try to isolate this issues, too.

spex66 avatar Apr 21 '17 15:04 spex66

Have you found a solution? Looks like that domain and path are ignored by add_cookie method.

MarcoG3 avatar Jul 14 '17 16:07 MarcoG3