chrome init a browser with cookie

#encoding: utf-8
require "watir-webdriver"
#b = Watir::Browser.new(:firefox, {:profile => 'default'}) # watir webdriver


# Which is going to create a new user data directory where all the cookies, bookmarks, cache etc. 
# will be stored. Basically, create a new profile. 
# If such a folder doesn't exist, it will create it. 
# If it does exist, it will load the cookies/all related files from it.

# C:\Users\{replace_with_your_username}\AppData\Local\Google\Chrome\User Data
# cmd command: chrome --user-data-dir="f:/desktop/Chrome/User Data"
user_data = 'C:\Users\dengbeiquan\AppData\Local\Google\Chrome\User Data'
b = Watir::Browser.new :chrome, :switches => ["--user-data-dir=#{user_data}"] # same philosophy for selenium, just a bit of a different syntax.
b.goto 'www.baidu.com'
puts b.title

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章