如何从python中的webdriver删除Firefox cookie? [英] How to delete Firefox cookies from webdriver in python?

查看:146
本文介绍了如何从python中的webdriver删除Firefox cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我无法从webdriver中删除FF cookie时.当我使用.delete_all_cookies方法时,它将返回None.当我尝试get_cookies时,出现以下错误:

when I can't delete FF cookies from webdriver. When I use the .delete_all_cookies method, it returns None. And when I try to get_cookies, I get the following error:

webdriver_common.exceptions.ErrorInResponseException: Error occurred when processing
packet:Content-Length: 120
{"elementId": "null", "context": "{9b44672f-d547-43a8-a01e-a504e617cfc1}", "parameters": [], "commandName": "getCookie"}
response:Length: 266
{"commandName":"getCookie","isError":true,"response":{"lineNumber":576,"message":"Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.host]","name":"NS_ERROR_FAILURE"},"elementId":"null","context":"{9b44672f-d547-43a8-a01e-a504e617cfc1} "}

我该如何解决?

更新:

这是在不做任何修改的情况下干净地安装webdriver发生的.我在另一篇文章中提到的更改是在发布此帖子之后进行的(我正在尝试自己解决此问题).

This happens with clean installation of webdriver with no modifications. The changes I've mentioned in another post were made later than this post being posted (I was trying to fix the issue myself).

推荐答案

嗯,我实际上没有与Webdriver一起工作,所以这可能完全没有帮助...但是在您的其他文章中,您提到您是尝试修改删除cookie webdriver js函数.在修改删除功能之前,get_cookies是否失败?如果在删除Cookie之前获得Cookie,会发生什么情况?我猜想您在webdriver-read-only \ firefox \ src \ extension \ components \ firefoxDriver.js中对删除功能所做的修改可能会破坏删除功能.您是在进行调试时还是在驱动程序告诉它删除Cookie时,是否真的希望浏览器本身显示弹出窗口?如果这个修改失败了,我不会感到惊讶.

Hmm, I actually haven't worked with Webdriver so this may be of no help at all... but in your other post you mention that you're experimenting with modifying the delete cookie webdriver js function. Did get_cookies fail before you were modifying the delete function? What happens when you get cookies before deleting them? I would guess that the modification you're making to the delete function in webdriver-read-only\firefox\src\extension\components\firefoxDriver.js could break the delete function. Are you doing it just for debugging or do you actually want the browser itself to show a pop up when the driver tells it to delete cookies? It wouldn't surprise me if this modification broke.

我真正的建议虽然实际上是开始使用Selenium而不是Webdriver,因为它已在当前版本中停产,或演变为Selenium.硒的开发更加积极,并具有相当活跃和反应灵敏的形式.在合并过程中,它将继续开发并保持稳定,而我认为Webdriver可能没有那么多的错误修正.我已经成功地使用了控制Cookie的Selenium命令.他们似乎正在修改其文档,由于某种原因,它们没有指向Python API的链接,但是如果您下载selenium rc,则可以在selenium-client-driver-python中找到Python API文档,您将看到那里是控制cookie的5种左右有用的好方法,如果您要删除名称与某个正则表达式匹配的所有cookie,则可以在自己的自定义Python方法中使用这些方法.如果出于某种原因您确实希望浏览器也对被删除的cookie发出Alert()信息,则可以通过从python方法获取cookie名称/值,然后将其传递给selenium的getEval()语句来执行,以实现此目的.您将其喂入的任意js(例如"alert()"). ...如果您采取硒途径,如果遇到阻滞剂,请随时与我联系,我可能会为您提供帮助.

My real advice though would be actually to start using Selenium instead of Webdriver since it's being discontinued in it's current incarnation, or morphed into Selenium. Selenium is more actively developed and has pretty active and responsive forms. It will continue to be developed and stable while the merge is happening, while I take it Webdriver might not have as many bugfixes going forward. I've had success using the Selenium commands that control cookies. They seem to be revamping their documentation and for some reason there isn't any link to the Python API, but if you download selenium rc, you can find the Python API doc in selenium-client-driver-python, you'll see there are a good 5 or so useful methods for controlling cookies, which you use in your own custom Python methods if you want to, say, delete all the cookies with a name matching a certain regexp. If for some reason you do want the browser to alert() some info about the deleted cookies too, you could do that by getting the cookie names/values from the python method, and then passing them to selenium's getEval() statement which will execute arbitrary js you feed it (like "alert()"). ... If you do go the selenium route feel free to contact me if you get a blocker, I might be able to assist.

这篇关于如何从python中的webdriver删除Firefox cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆