![](/img/trans.png)
[英]Selenium::WebDriver::Error::ElementNotVisibleError while looping to click button using Watir
[英]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(以使到期工作)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.