watir-webdriver cookie jar saving and loading

前端 未结 2 431
半阙折子戏
半阙折子戏 2021-02-10 01:39

I\'m surprised there didn\'t seem to be much discussion on this.

in Mechanize I can easily read an entire cookie jar from the browser, store it to a file, and load it in

2条回答
  •  清歌不尽
    2021-02-10 02:22

    browser = Watir::Browser.new :firefox
    browser.goto 'http://google.com'
    # save cookies
    saved_cookies = browser.cookies.to_a
    # clear and get new cookies
    browser.cookies.clear
    browser.goto 'http://google.com'
    # set new cookies
    browser.cookies.clear
    saved_cookies.each do |saved_cookie|
      browser.cookies.add(saved_cookie[:name], saved_cookie[:value])
    end
    

提交回复
热议问题