代码:
结果:
PS E:\30.Study\30.自动化测试\99.零基础入门 Python Web 自动化测试\10.seleniumCodePractice> & "C:/Program Files/Python38/python.exe" "e:/30.Study/30.自动化测试/99.零基础入门 Python Web 自动化测试/10.seleniumCodePractice/202006/open_browser.py"
Traceback (most recent call last):
  File "e:/30.Study/30.自动化测试/99.零基础入门 Python Web 自动化测试/10.seleniumCodePractice/202006/open_browser.py", line 13, in <module>
    driver.close()
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 688, in close
    self.execute(Command.CLOSE)
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Unable to get browser
PS E:\30.Study\30.自动化测试\99.零基础入门 Python Web 自动化测试\10.seleniumCodePractice> 
原因分析:
转自:https://www.cnblogs.com/testlife007/p/5545830.html
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.即(https://blog.csdn.net/Justin_1011/java/article/details/51851691)
解决方案:
1.修改注册表(Ctrl+R --> regedit--> Enter)
2.修改注册表路径: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
  如果FeatureControl下没有FEATURE_BFCACHE,就以FEATURE_BFCACHE为名new一个key!并在其下创建一个DWORD,取名为:iexplore.exe,value为0。
特别注意:
若想正常使用WebDriver,请确保你的浏览器选项中security中各个zone的Protected Mode都是勾选着/非勾选着的,一定要统一才行!否则WebDriver将无法打开浏览器,会有如下异常:
System.InvalidOperationException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver)
补充:
IE11 webdriver 驱动下载:
https://dl.pconline.com.cn/download/771640-1.html
Iwebdriver启动IE11:
https://www.cnblogs.com/xmmc/p/7634431.html
Python Web 自动化测试2之IE11异常(Unable to get browser)
原文:https://www.cnblogs.com/hadas/p/13167909.html