ruby – 使用watir webdriver或selenium设置cookie

ruby – 使用watir webdriver或selenium设置cookie,第1张

概述创建驱动程序: – profile = Selenium::WebDriver::Firefox::Profile.new driver = Watir::Browser.new :firefox, profile: profileurl= 'http://www.example.com' 添加cookies: – driver.cookies.add("test","1",{expire 创建驱动程序: –

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 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 urldriver.cookies.add("test",{expires: 10.days.from_Now})

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

driver.cookies.to_a

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

总结

以上是内存溢出为你收集整理的ruby – 使用watir webdriver或selenium设置cookie全部内容,希望文章能够帮你解决ruby – 使用watir webdriver或selenium设置cookie所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1287160.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存