如何将Ruby的Selenium WebDriver中的所有cookie保存到一个txt文件中,然后再加载它们?我找不到同时导出和导入的答案
在python中看起来很容易做到这一点,如何在RUBY中做到这一点呢?
How to save and load cookies using Python + Selenium WebDriver
import pickle
import selenium.webdriver
driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))编辑:我只使用Selenium WebDriver (没有水豚等)
发布于 2019-05-28 17:39:31
在测试中,您可以使用gem show_me_the_cookies (包装器/适配器)
cookies = show_me_the_cookies # => [{:name, :domain, :value, :expires, :path, :secure}]
# here you can write them as you like
# and then load and
cookies.each{|c|
create_cookie(c[:name], c[:value], path: c[:path], domain: c[:domain]) # etc.
}没有gem,您可以直接调用selenium驱动程序:
driver = Capybara.current_session.driver # or get your selenium driver other way if not using capybara
cookies = driver.browser.manage.all_cookies
# be sure that you've visited a page in your app, selenium cannot create cookies at `about:blank`
driver.browser.manage.add_cookie(name: ..., value:...)https://stackoverflow.com/questions/56338704
复制相似问题