[英]Using watir-webdriver to set cookies on internet explorer
I am trying to set cookies on Internet Explorer from a Cucumber acceptance test. 我正在尝试通过Cucumber接受测试在Internet Explorer上设置Cookie。
Here is the first thing that I tried: 这是我尝试的第一件事:
browser.cookies.add("my.cookie","90",{:path => "/", :expires => expiredTime})
Here is the second thing: 这是第二件事:
browser.driver.manage.add_cookie(name:"my.cookie", value:"90", expires:expired_time)
Both of these approaches cause the same exception: 这两种方法都会导致相同的异常:
(Selenium::WebDriver::Error::NoSuchDocumentError) Unable to add cookie to page
I only get this exception when using Internet Explorer, but not Firefox. 我只有在使用Internet Explorer而不是Firefox时才会遇到此异常。
I am using Windows 7, IE 8, 64-bit. 我正在使用Windows 7,IE 8、64位。
Some of my gems: selenium-webdriver (2.25.0) watir-webdriver (0.6.1) cucumber (1.2.1) 我的一些瑰宝:硒webdriver(2.25.0)瓦特尔webdriver(0.6.1)黄瓜(1.2.1)
Thanks in advance for any advice on fixing this issue. 在此先感谢您提供解决此问题的建议。
I had exactly the same issue on Win7 / IE9. 我在Win7 / IE9上遇到了完全相同的问题。 I figured out that adding the cookies failed when the page the browser was on had no-cache headers set.
我发现,当浏览器所在的页面设置无缓存标题时,添加cookie失败。 We created an empty page on our server with far-future cache headers, and setting cookies while on that page works.
我们在服务器上创建了一个空的页面,其中包含远距离的缓存头,并在该页面上正常工作时设置cookie。
I do not know which particular header prevents adding cookies. 我不知道哪个特定的标题阻止添加cookie。 Since you probably need to move to a different page to set the cookies, it's worth using one with far-future headers to speed up loading.
由于您可能需要移动到其他页面来设置Cookie,因此值得使用带有远距离标题的页面来加快加载速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.