我创建了一些Selenium Python脚本,该脚本在现有的Firefox浏览器中打开一个链接并执行一些操作。我需要使用相同的浏览器,因为我已经在其上安装了addBlock插件,并且我不想每次都运行新的浏览器(未安装addBlock)
在Firefox 63.0上运行正常 今天,他们将Firefox的版本更新为63.0.1,并且停止工作。尝试运行
driver.get ("https://blablala.com")
给予
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Browsing context has been discarded
我尝试了http://www.yandex.ru/,http://www.google.com
如果要运行没有addBlock插件的浏览器,则不会出现此类错误,Selenium会打开此站点。
在Firefox更新后,有人遇到过类似的事情吗?应该是什么? Selenium WebDriver的任何错误(没有新版本,我使用最新的v0.23.0)?
代码(如何附加到现有会话的部分来自此站点。
def attach_to_session(executor_url, session_id):
original_execute = WebDriver.execute
def new_command_execute(self, command, params=None):
if command == "newSession":
# Mock the response
return {'success': 0, 'value': None, 'sessionId': session_id}
else:
return original_execute(self, command, params)
# Patch the function before creating the driver object
WebDriver.execute = new_command_execute
driver = webdriver.Remote(command_executor=executor_url,
desired_capabilities={})
driver.session_id = session_id
# Replace the patched function with original function
WebDriver.execute = original_execute
return driver
driver = attach_to_session('http://127.0.0.1:50688', '560a911b-c75a-4c55-
863e-b532b8f07365')
driver.get ("https://blablablabla")