使用Capybara删除浏览器Cookies [英] Delete browser Cookies using Capybara
问题描述
当我更改了最大化浏览器窗口的代码时,无法使用水豚删除浏览器cookie。
最初我使用下面的代码。在删除cookie的情况下它可以正常工作
Deleting browser cookies using capybara is not working while i changed my code for maximizing browser window. Initially i used following code.It works properly in case of deleting cookies
browser = Capybara.current_session.driver.browser
Capybara.default_wait_time = 12
browser.manage.delete_all_cookies
根据我需要最大化浏览器window.so的要求,所以我更改了以下代码,并在 browser.manage.delete_all_cookies
As per the requirement i need to maximize the browser window.so i changed the above code as follows and getting error in place of browser.manage.delete_all_cookies
browser = Capybara.current_session.driver.browser.manage.window.resize_to(1600, 800)
Capybara.default_wait_time = 12
browser.manage.delete_all_cookies
'startTesting':Undefined method 'manage' for nilClass(noMethodError)
推荐答案
问题是浏览器
被设置为 resize_to
方法,该方法基于错误消息为 nil
。
The problem is that browser
is being set to the value returned by the resize_to
method, which based on the error message is nil
.
您应调整类似于删除Cookie的窗口:
You should resize the window similar to how you are deleting the cookies:
browser = Capybara.current_session.driver.browser
browser.manage.window.resize_to(1600, 800)
Capybara.default_wait_time = 12
browser.manage.delete_all_cookies
请注意,调整大小是在自己的行上进行的(即,不是设置浏览器
变量的行的一部分)。
Notice that the resizing is on its own line (ie not part of the line that sets the browser
variable).
这篇关于使用Capybara删除浏览器Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!