Selenium: Options.getCookie should return null if cookie not found.

Created on 16 Aug 2018  路  5Comments  路  Source: SeleniumHQ/selenium

Meta -

OS:

OSX 10.13

Selenium Version:

4.0.0-alpha.1

Browser:

Firefox developer edition

Browser Version:

62.0b15

Expected Behavior -

If cookie is not exists, I should get null just like official document said.
https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html

  • Retrieves the cookie with the given name. Returns null if there is no such cookie. The cookie will be returned as a JSON object as described by the WebDriver wire protocol.*

Actual Behavior -

I got an error:

    NoSuchCookieError: No cookie with name sbet

      at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:550:15)
      at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:542:13)
      at Executor.execute (node_modules/selenium-webdriver/lib/http.js:468:26)

Steps to reproduce -

I use Javascript and [email protected]

  1. Initialize Driver
  2. call await driver.manage().getCookie('XXX')
  3. I should got a null in step 2 but I got NoSuchCookieError.
C-nodejs

Most helpful comment

That's up to the maintainer of the nodejs code. If it's to be nil, then the code needs updating. If it's supposed to throw an error then the documentation needs updating. @jleyba

All 5 comments

The w3c spec says to throw the error you are getting, so that's at least behaving correctly. It looks like the getCookie command needs to add the NoSuchCookie error to the erros it catches here https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/lib/webdriver.js#L1207

@lmtierney yes, I also checked the source code. So you mean the getCookie command need to return null instead of throw NoSuchCookie error? If yes, I probably can help to fix it.

That's up to the maintainer of the nodejs code. If it's to be nil, then the code needs updating. If it's supposed to throw an error then the documentation needs updating. @jleyba

@Harsha509, thank you for fixing this!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings