加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 使用watir webdriver或selenium设置cookie

发布时间:2020-12-17 02:54:57 所属栏目:百科 来源:网络整理
导读:创建驱动程序: – profile = Selenium::WebDriver::Firefox::Profile.new driver = Watir::Browser.new :firefox,profile: profileurl= 'http://www.example.com' 添加cookies: – driver.cookies.add("test","1",{expires: 10.days.from_now})driver.goto
创建驱动程序: –

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",{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",{expires: 10.days.from_now})

现在它应该出现在你所在的同一个域上:

driver.cookies.to_a

假设您需要active_support / time(以使到期工作).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读