Some time ago I edited version 2.5.3 of java selenium standalone to remove the error message "unable to set cookie" that occurs when trying to set a cookie prior to loading a page from the domain that the cookie pertains to. That modification involved editing some javascript to remove the error checking.
Is it possible to do a similar modification in selenium 3.7.1 for the java build towards altering the java chrome?
Currently I'm using the following maven dependencies. I haven't modified the open source yet.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
I would be interested to know why selenium handles cookies differently than the browser. When you load a page on a browser, the cookies are already available on the first load of the page. With selenium the cookies are only available after loading the given domain page a first time and then a second load of the given domain page is required to have the cookies recognized.
I'm assuming there must be some logical reason why things must be implemented this way. Does anyone know why?
My continuing research into modifying selenium 3.7.1:
I've found the error message l[25] = "unable to set cookie"; in the following java and javascript files in the selenium github code
grep -rnw './' -e "unable to set cookie"
./javascript/atoms/error.js:142: UNABLE_TO_SET_COOKIE: 'unable to set cookie',
./javascript/node/selenium-webdriver/test/lib/error_test.js:61: test('unable to set cookie', error.UnableToSetCookieError);
./javascript/node/selenium-webdriver/test/lib/error_test.js:115: test(error.UnableToSetCookieError, 'unable to set cookie');
./javascript/node/selenium-webdriver/test/lib/error_test.js:189: test('unable to set cookie', error.UnableToSetCookieError);
./javascript/node/selenium-webdriver/lib/error.js:474: ['unable to set cookie', UnableToSetCookieError],
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:245: .add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
./javascript/node/selenium-webdriver/lib/error.js:474 has the following code
/**
* A request to set a cookie’s value could not be satisfied.
*/
class UnableToSetCookieError extends WebDriverError {
/** @param {string=} opt_error the error message, if any. */
constructor(opt_error) {
super(opt_error);
}
} has the
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:245 has the following code
public static final int UNABLE_TO_SET_COOKIE = 25;
.add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
Cleary UnableToSetCookieException may be of importance. So I've greped the following
grep -rnw './' -e "UnableToSetCookieException"
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:45:import org.openqa.selenium.UnableToSetCookieException;
./java/client/src/org/openqa/selenium/remote/ErrorCodes.java:245: .add(new KnownError(UNABLE_TO_SET_COOKIE, "unable to set cookie", 500, UnableToSetCookieException.class, true, true))
./java/client/src/org/openqa/selenium/BUCK:128: 'UnableToSetCookieException.java',
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:25:public class UnableToSetCookieException extends WebDriverException {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:26: public UnableToSetCookieException() {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:29: public UnableToSetCookieException(String message) {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:33: public UnableToSetCookieException(Throwable cause) {
./java/client/src/org/openqa/selenium/UnableToSetCookieException.java:37: public UnableToSetCookieException(String message, Throwable cause) {
./java/client/test/org/openqa/selenium/remote/ErrorHandlerTest.java:54:import org.openqa.selenium.UnableToSetCookieException;
./java/client/test/org/openqa/selenium/remote/ErrorHandlerTest.java:460: exceptions.put(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class);
Clearly the following class throws the cookie exception
/**
* Thrown when a driver fails to set a cookie.
*
* @see org.openqa.selenium.WebDriver.Options#addCookie(Cookie)
*/
public class UnableToSetCookieException extends WebDriverException {
public UnableToSetCookieException() {
}
public UnableToSetCookieException(String message) {
super(message);
}
However I'm not yet understanding how or if this relates to the addCookie method which generates the error.
driver.manage().addCookie(aCookie);
I'll continue to update my research here as I learn more...