Selenide: Unable to set cookie to browser if used combination of params -Dselenide.fileDownload=PROXY and -Dremote

Created on 12 Apr 2018  路  7Comments  路  Source: selenide/selenide

The problem

We used Selenide with 'Selenoid' grid using the standard parameter -Dremote.
For downloading files without href attribute, i tried to use parameter -Dselenide.fileDownload=PROXY, so, a combination of these parameters results in an error in case that i try to add cookie: WebDriverException: unable to set cookie / Failed to set the 'cookie' property on 'Document': Access is denied

Details

1) Main page of web-app loaded (we can see it in SelenoidUI, also getWebDriver().getCurrentUrl() returns the correct url)
In case that i tried to add cookie:

getWebDriver().manage().addCookie(new Cookie("user", encodedCookie));

I get an error

org.openqa.selenium.WebDriverException: unable to set cookie
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Linux 3.10.0-514.21.1.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'dmitriis-mbp.it.lan', ip: 'fe80:0:0:0:46a:d408:4f35:7c9%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: /tmp/.org.chromium.Chromium...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 65.0.3325.181, webStorageEnabled: true}
Session ID: a462821b22024b0f420588e02fc9e1c0ab4b8e7235dd6ac6b46542ac02f4dcc6

    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.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions.addCookie(RemoteWebDriver.java:731)

if i tried to add cookie through JS, i get an error

Failed to set the 'cookie' property on 'Document': Access is denied

Tell us about your environment

  • Selenide v. 4.10.01
  • chrome=65.0.3325.181
  • chromedriver=2.37.544315
  • selenium:3.8.1
  • docker image with browser: selenoid/chrome:65.0

NOTE!

PROXY w/o remote webDriver works well. Also, remote webDriver w/o PROXY works well too.

question waiting-for-author

Most helpful comment

@dtuchs are you on the DOMAIN you are trying to assign a cookie on? you cannot set cookies for domains which you currently do not reside on with selenium as per W3C standards.

for example, try adding a cookie for "example.com" with the browser currently on "somethingelse.com" will never work. you need to do the following:

  • Navigate to *@domain.com
  • addCookie();
  • Refresh the page etc...

All 7 comments

@dtuchs Is the issue still valid? I tried to add cookie to a remote browser - and it worked well. Thought, I used usual Selenium Grid, not Selenoid.

This is happening to me too. I'm trying to set a multi-part cookie:

remoteWebDriver.manage().addCookie(
    new Cookie(
        "PHASED_SWITCH",
        "100", ".example.com", "/", null)
);

And getting the same error

@Dazzla

  1. Do you use Selenium Grid or Selenoid?
  2. Does it run on localhost or another machine?
  3. What means "multi-part cookie"?

@asolntsev unfortunately this problem is still relevant for the Selenide version 4.12.3 and Selenoid (running on remote machine)

@dtuchs could you please create simple project to reproduce issue and share it with us on github?
It will significantly help us to investigate the issue.

@dtuchs are you on the DOMAIN you are trying to assign a cookie on? you cannot set cookies for domains which you currently do not reside on with selenium as per W3C standards.

for example, try adding a cookie for "example.com" with the browser currently on "somethingelse.com" will never work. you need to do the following:

  • Navigate to *@domain.com
  • addCookie();
  • Refresh the page etc...

Closing due to inactivity. Feel free to reopen if we get new information.

Was this page helpful?
0 / 5 - 0 ratings