本地HTML页面上的IEDriverServer以NoSuchWindowException结束:无法获取浏览器

时间:2015-02-05 14:17:10

标签: selenium internet-explorer-11 python-3.4

我在Win8.1上使用32位IE11。 我有一些Selenium脚本(Python绑定),我在IE11上执行。

使用IEDriverServer,我已经完成了InternetExplorerDriver-wiki page上建议的所有步骤,并且通常IEDriver工作正常。

但是,如果我尝试获取本地HTML页面,例如:

from selenium import webdriver
ie = webdriver.Ie()
url = "file:///D:/dev/proof_of_concept/html/liki.html"
ie.get(url)
print(ie.current_url)

我得到了这个例外:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 426, in current_url
return self.execute(Command.GET_CURRENT_URL)['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: 'Unable to get browser'

关于一般IE11问题(使用注册表解决方案)有许多线索,但我无法通过本地页面找到针对此特定问题的任何解决方案。

我不知道有哪些限制或与安全区相关的内容?

谢谢!

1 个答案:

答案 0 :(得分:4)

IE驱动程序不支持使用file://协议打开HTML文档。造成这种情况的原因有很多,但有两个特别突出。首先,对于使用file://协议在IE中打开的文档,默认情况下禁用JavaScript。由于IE驱动程序需要JavaScript才能正常运行,因此这是一个非启动程序。其次,使用file://协议打开的文档在单独的保护模式区域中打开,该区域通常不显示在“选项”对话框中。因此,不可能避免越过保护模式边界,并且当越过这样的边界时,驱动程序使用的COM对象自动化IE变为孤立。

启动一个简单的Web服务器并不难用于提供您感兴趣的自动化文档。这将是正确的前进方式。