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'
答案 0 :(得分:1)
您似乎在尝试访问任何URL之前都要设置Cookie。
如this article on jamescroft.com和此Selenium issue on GitHub所述,您需要执行以下操作:
visit 'https://your_website.com'
browser = Capybara.current_session.driver.browser
browser.manage.add_cookie :name => "introduction_done", :value => "yes"