使用 watir webdriver 或 selenium 设置 cookie
Set cookie using watir webdriver or selenium
创建驱动程序:-
profile = Selenium::WebDriver::Firefox::Profile.new
driver = Watir::Browser.new :firefox, profile: profile
url= 'http://www.example.com'
添加 cookies:-
driver.cookies.add("test","1",{expires: 10.days.from_now})
driver.goto url
响应中未返回我的 cookie。
如果我在 cookie 中添加域。
driver.cookies.add("test","1",{expires: 10.days.from_now, domain: 'example.com'})
它说的错误如下:-
Selenium::WebDriver::Error::InvalidCookieDomainError: You may only set cookies for the current domain
谁能帮我解决这个问题?
您必须在为其设置 cookie 的域中,因此请尝试:
driver.goto url
driver.cookies.add("test","1",{expires: 10.days.from_now})
现在,当您位于同一域时,它应该会显示:
driver.cookies.to_a
这是假设您需要 active_support/time(以使到期有效)。
创建驱动程序:-
profile = Selenium::WebDriver::Firefox::Profile.new
driver = Watir::Browser.new :firefox, profile: profile
url= 'http://www.example.com'
添加 cookies:-
driver.cookies.add("test","1",{expires: 10.days.from_now})
driver.goto url
响应中未返回我的 cookie。
如果我在 cookie 中添加域。
driver.cookies.add("test","1",{expires: 10.days.from_now, domain: 'example.com'})
它说的错误如下:-
Selenium::WebDriver::Error::InvalidCookieDomainError: You may only set cookies for the current domain
谁能帮我解决这个问题?
您必须在为其设置 cookie 的域中,因此请尝试:
driver.goto url
driver.cookies.add("test","1",{expires: 10.days.from_now})
现在,当您位于同一域时,它应该会显示:
driver.cookies.to_a
这是假设您需要 active_support/time(以使到期有效)。