代码:
结果:
PS E:30.Study30.自动化测试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 FilesPython38libsite-packagesseleniumwebdriver
emotewebdriver.py", line 688, in close
self.execute(Command.CLOSE)
File "C:Program FilesPython38libsite-packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:Program FilesPython38libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Unable to get browser
PS E:30.Study30.自动化测试99.零基础入门 Python Web 自动化测试10.seleniumCodePractice>
原因分析:
转自:https://www.cnblogs.com/testlife007/p/5545830.html
官方解决方案:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
Required Configuration
- The IEDriverServer exectuable must be downloaded and placed in your PATH.
- On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
- Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
- The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
- For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor is
HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerMainFeatureControlFEATURE_BFCACHE
. For 64-bit Windows installations, the key isHKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet ExplorerMainFeatureControlFEATURE_BFCACHE
. Please note that theFEATURE_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 namediexplore.exe
with the value of 0.
即(https://blog.csdn.net/Justin_1011/java/article/details/51851691)
解决方案:
1.修改注册表(Ctrl+R --> regedit--> Enter)
2.修改注册表路径: HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet ExplorerMainFeatureControlFEATURE_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: