RahulOnRails
RahulOnRails

Reputation: 6542

Capybara + Unable to set cookie while execution of automation script

browser = Capybara.current_session.driver.browser
browser.manage.add_cookie :name => "introduction_done", :value => "yes"
#even tired this one as well
browser.manage.add_cookie name: "introduction_done", value: "yes"

Got the Error

# --- Caused by: ---
# Selenium::WebDriver::Error::NoSuchCollectionError:
# unable to set cookie
# (Session info: chrome=67.0.3396.99)
# (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.15.0-29-generic x86_64)
# /home/.rvm/gems/ruby-2.4.3/gems/selenium-webdriver-3.13.1/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'

Upvotes: 0

Views: 669

Answers (1)

fabdurso
fabdurso

Reputation: 2444

It looks like you are trying to set the cookie before visiting any URL.

As explained on this article on jamescroft.com and this Selenium issue on GitHub, you need to do something like:

visit 'https://your_website.com'
browser = Capybara.current_session.driver.browser
browser.manage.add_cookie :name => "introduction_done", :value => "yes"

Upvotes: 1

Related Questions