Search code examples
watirwatir-webdriver

How to load cookies before visiting webpage in Watir


So I know I can load cookies in Watir from a file using:

browser.cookies.load("cookies")

The problem is that this will only load cookies for the page I am currently on. So if I want to load the cookies for a webpage I have to visit it before doing so. Is there any way to load cookies before you visit the page?


Solution

  • Watir mimics what a user can do on a browser. A user must be on a page to load cookies for it, so also does Watir/Selenium. You would need to go to the site, load the cookies then you can refresh page / navigate to where on the site you need to be.