Search code examples
rubywatir

How to set cookies in Watir


I have to scrap a site using Watir and Chrome browser. The site needs multiple location selectors to open. I need to set the location parameters in the cookie.

I have used the method listed in this URL: http://watir.com/guides/cookies/

On running the code I got the following error: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs. (Selenium::WebDriver::Error::NoScriptResultError)


Solution

  • browser.cookies.add 'foo', 'bar', path: '/', expires: 10.days.from_now, secure: true
    

    Reference: Watir