browser.cookies.clear does not work on Edge browser

Confirmed Issue #14838528 • Assigned to Stanley H.

Details

Author
Mark D.
Created
Nov 27, 2017
Privacy
This issue is public.
Found in
  • Microsoft Edge
Found in build #
15.15063
Reports
Reported by 3 people

Sign in to watch or report this issue.

Steps to reproduce

Issue
browser.cookies.clear does not work.
On FF/Chrome I can use this and it will delete all cookies.
On Edge I get this error

irb(main):001:0> require 'watir'
=> true
irb(main):002:0> browser = Watir::Browser.new :edge
=> #<Watir::Browser:0x..fa0b676a0 url="about:blank" title="">
irb(main):003:0> browser.cookies.clear
Selenium::WebDriver::Error::UnknownError: Unknown error
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/http/common.rb:81:in `new'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/http/common.rb:81:in `create_response'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/bridge.rb:168:in `execute'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/w3c/bridge.rb:535:in `execute'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/remote/w3c/bridge.rb:326:in `delete_all_cookies'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/common/w3c_options.rb:38:in `delete_all_cookies'
        from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.9.1/lib/watir/cookies.rb:92:in `clear'
        from (irb):3
        from C:/Ruby23/bin/irb.cmd:19:in `<main>'
irb(main):004:0>

When I first navigate to the website and then perform the clear command, I’m not getting any error, but the cookies are still in place. (see attached screenshot)

Attachments

Comments and activity

  • Microsoft Edge Team

    Changed Assigned To to “Steven K.”

  • Watir docs for reference: http://www.rubydoc.info/gems/watir-webdriver/Watir/Cookies

    Besides .clear I also tried .delete ‘name’ both did not delete the cookie.
    Here is another example of a website that is not accessible for the outside, but it demonstrates the issue:

    irb(main):014:0> browser :edge
    No default device, nor a selected device was set. Browser default settings will be loaded. More info: http://testautomation.info/Lapis_Lazuli:Device_Simulation
    2017-11-28 09:55:17 INFO Watir Creating Browser instance of edge with user provided options: {}
    2017-11-28 09:55:17 INFO Watir Creating Browser instance with Watir processed options: {:http_client=>#, :desired_capabilities=>#"MicrosoftEdge", :version=>"", :platform=>:windows, :javascript_enabled=>true, :css_selectors_enabled=>true, :takes_screenshot=>true, :native_events=>false, :rotatable=>false, :firefox_profile=>nil, :proxy=>nil}>}
    => #, @assertions=5>
    irb(main):015:0> Watir.logger.level = :info
    => :info
    irb(main):016:0> browser.goto "https://[INTERNAL_URL]"
    => "https://[INTERNAL_URL]"
    irb(main):017:0> browser.cookies.to_a
    NoMethodError: undefined method `map' for nil:NilClass
            from C:/Ruby23/lib/ruby/gems/2.3.0/gems/selenium-webdriver-3.7.0/lib/selenium/webdriver/common/options.rb:91:in `all_cookies'
            from C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.9.1/lib/watir/cookies.rb:21:in `to_a'
            from (irb):17
            from C:/Ruby23/bin/irb.cmd:19:in `'
    irb(main):018:0> browser.find(:like => [:input, 'data-mp-l10n', 'Agree']).click
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#tag_name` after `#wait_for_exists`
    2017-11-28 09:56:54 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#tag_name` has been completed
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#attribute_value` after `#wait_for_exists`
    2017-11-28 09:56:54 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#attribute_value` has been completed
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#tag_name` after `#wait_for_exists`
    2017-11-28 09:56:54 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :index=>0}>#tag_name` has been completed
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#visible?` after `#assert_exists`
    2017-11-28 09:56:54 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#visible?` has been completed
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#click` after `#wait_for_enabled`
    2017-11-28 09:56:54 INFO Watir -> `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#enabled?` after `#assert_exists` (as a prerequisite for a previously specified execution)
    2017-11-28 09:56:54 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#enabled?` has been completed
    2017-11-28 09:56:55 INFO Watir <- `#"//input[contains(concat('', normalize-space(@data-mp-l10n), ''), 'Agree')]", :tag_name=>"input", :index=>0}>#click` has been completed
    => nil
    irb(main):019:0> browser.cookies.to_a
    => [{:name=>"acceptedCookies", :value=>"y", :path=>"/", :domain=>"{INTERNAL_URL}", :expires=>2018-11-28 09:56:55 +0100, :secure=>false}]
    irb(main):020:0> browser.cookies.clear
    => nil
    irb(main):021:0> browser.cookies.to_a
    => [{:name=>"acceptedCookies", :value=>"y", :path=>"/", :domain=>"[INTERNAL_URL]", :expires=>2018-11-28 09:56:55 +0100, :secure=>false}]
    irb(main):022:0> browser.cookie.delete 'acceptedCookies'
    NoMethodError: undefined method `cookie' for #
            from C:/Ruby23/lib/ruby/gems/2.3.0/gems/lapis_lazuli-2.0.1/lib/lapis_lazuli/browser.rb:204:in `method_missing'
            from (irb):22
            from C:/Ruby23/bin/irb.cmd:19:in `'
    irb(main):023:0> browser.cookies.delete 'acceptedCookies'
    => nil
    irb(main):024:0> browser.cookies.to_a
    => [{:name=>"acceptedCookies", :value=>"y", :path=>"/", :domain=>"[INTERNAL_URL]", :expires=>2018-11-28 09:56:55 +0100, :secure=>false}]
    irb(main):025:0>
    
  • Microsoft Edge Team

    Changed Assigned To to “Stanley H.”

    Changed Status to “Fixed”

  • this is now fixed.

  • Hi Stanley, that is awesome news, this will make my life much easier again.
    Now I should be able again to run all login tests
    Where is this fixed?

    • Windows update…
    • Edge version…
    • Webdriver version…
  • The reason I ask is because with my current setup (webdriver 16.16299, Edge 16.16299, Win10 1709 OS Build 16299.125) I still see the same issue.

  • I had to look up what that new status means. Found the answer here:
    https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/15907408/

    Issue still found in webdriver 16.16299, Edge 16.16299, Win10 1709 OS Build 16299.251
    Could you please mention in which (public available) version this should be fixed?

  • I am also having issues with other cookie tasks such as Add Cookies. Same documentation as above. Will this fix address those as well?
    And can we get an estimated release date?
    Thank you!

  • Retested with Win10 version 1803 build 17134.48
    Edge 17.17134
    But this issue is still present.
    @pbstools in what version can we expect the fix?

  • I am also having problems clearing cookies using:

    • Edge driver 17134
    • Selenium 3.12.0
    • Microsoft Edge 42.17134.1.0
    • Microsoft EdgeHTML 17.17134
    • Intern 4.2.0

    Code sample

    The cookie is only cleared when I execute the

    document.cookie = ...
    

    code in the browser. The clearCookies() command does not work. clearCookies() works fine in Chrome, Firefox and IE 11.

        afterEach: function() {
          // Clear cookies to return to clean state for other tests
          const dfd = this.async();
          this.remote.clearCookies()
            .getCookies()
            .then((cookies) => {
              // cookies HAVE NOT been cleared by clearCookies()
            })
            .execute(function() {
              return document.cookie;
            })
            .then((cookie) => {
              // cookies HAVE NOT been cleared by clearCookies()
            })
            .execute(function() {
              // name of cookie to clear is "validate"
              document.cookie = "validate" + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
            })
            .getCookies()
            .then((cookies) => {
              // cookies HAVE been cleared by manually setting document.cookie
            })
            .catch((err) => console.log(err))
            .finally(() => dfd.resolve());
        },
    
  • Microsoft Edge Team

    Changed Assigned To to “Stanley H.”

    Changed Status from “Fixed”

  • Hello Mark, Paul, Jason,

    I am seeing a little different behavior.  I tested using Mark’s original method using Ruby/Watir.  I see that the call to browser.cookies.clear appears to work.  However, the next call to cookies.to_a fails.  I have attached my irb console log file.

    require ‘watir’
    Watir.logger.level = :info
    browser = Watir::Browser.new :edge
    browser.goto ‘watir.com’
    browser.link(text: ‘documentation’).click
    puts browser.title
    browser.cookies.to_a
    // success
    browser.cookies.clear
    // seems to clear, but not certain
    browser.cookies.to_a
    // fail - receive NoMethodError here.
    browser.refresh
    browser.cookies.to_a
    // success
    browser.cookies.delete ‘_gid’
    browser.cookies.to_a
    // success - _gid is deleted
    browser.close

    Here is version information:
    Ruby version 2.5.1-2.

    gem list
    bigdecimal (default: 1.3.4)
    childprocess (0.9.0)
    cmath (default: 1.0.0)
    csv (default: 1.0.0)
    date (default: 1.0.0)
    dbm (default: 1.0.0)
    did_you_mean (1.2.0)
    etc (default: 1.0.0)
    fcntl (default: 1.0.0)
    ffi (1.9.25 x64-mingw32)
    fiddle (default: 1.0.0)
    fileutils (default: 1.0.2)
    gdbm (default: 2.0.0)
    io-console (default: 0.4.6)
    ipaddr (default: 1.2.0)
    json (default: 2.1.0)
    minitest (5.10.3)
    net-telnet (0.1.1)
    openssl (default: 2.1.0)
    power_assert (1.1.1)
    psych (default: 3.0.2)
    rake (12.3.0)
    rdoc (default: 6.0.1)
    rubyzip (1.2.1)
    scanf (default: 1.0.0)
    sdbm (default: 1.0.0)
    selenium-webdriver (3.13.0)
    stringio (default: 0.0.1)
    strscan (default: 1.0.0)
    test-unit (3.2.7)
    watir (6.11.0)
    webrick (default: 1.4.2)
    xmlrpc (0.3.0)
    zlib (default: 1.0.0)

    Steve

  • Also, the call to delete a specific cookie entry was successful.

  • Hi Steven,
    I looked at it again and indeed cookies seem to be cleared when I do browser.cookies.clear
    And indeed browser.cookies.to_a is failing on Edge when there are no cookies present.
    On Chrome I get an empty array
    irb(main):005:0> browser.cookies.to_a
    => []
    irb(main):006:0>

  • Even though I think browser.cookies.to_a should still return an empty array, I can work around this issue now with something like this:
    elm = browser.cookies.to_a rescue false

  • Yes, I agree.  We are investigating the issue of returning an error instead of an empty array indication.

    Thank you for the quick response and verifying the current status.  We will respond here with any updates.

    Steve

  • Microsoft Edge Team

    Changed Status to “Confirmed”

You need to sign in to your Microsoft account to add a comment.

Sign in