代碼:
結果:
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
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_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
. For 64-bit Windows installations, the key isHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_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_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