Capybara + 执行自动化脚本时无法设置 cookie

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"

收到错误

# --- 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'

您似乎在访问任何 URL.

之前尝试设置 cookie 如 this article on jamescroft.com and this Selenium issue on GitHub 中所述,您需要执行以下操作:

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