[英]Exception in Selenium webdriver(IE) in python
下面是我的 python 代碼,
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
print("brower1\n")
browser = webdriver.Ie('C:\Program Files (x86)\Internet Explorer\iexplore.exe')
print("brower2\n")
我在webdriver.Ie()
中遇到異常,在該print
語句print("brower2")
沒有執行之后......
下面提到的是我的異常錯誤,
Traceback (most recent call last):
File "automated_vpn.py", line 8, in <module>
browser = webdriver.Ie('C:\Program Files (x86)\Internet Explorer\iexplore.ex
e')
File "C:\Program Files (x86)\python\lib\site-packages\selenium\webdriver\ie\we
bdriver.py", line 91, in __init__
self.iedriver.start()
File "C:\Program Files (x86)\python\lib\site-packages\selenium\webdriver\commo
n\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Program Files (x86)\python\lib\site-packages\selenium\webdriver\commo
n\service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files
(x86)\Internet Explorer\iexplore.exe unexpectedly exited. Status code was: 1
請幫我解決這個問題...
Webdriver 應該是對應瀏覽器的驅動路徑。 可以在此處找到 IE 驅動程序文件。
我建議您下載 32 位 IE 驅動程序文件,解壓縮並將可執行文件放在您的程序文件夾中,然后將其鏈接如下:
browser = webdriver.Ie("C:\\Script path\\IEDriverServer.exe")
現在,當您運行腳本時,它應該會打開 IE 瀏覽器。
路徑應該有雙斜杠或者它應該有一個前導 r 像 r"c:\Program Files(x86)\file.exe"
但提供的路徑應該是 IE webdriver 服務器而不是 Internet Explorer。 從此處下載並將路徑添加到您的環境路徑變量或提供完整路徑。 上述鏈接中的此驅動程序已在 IE 7、8、9、10 和 11 上在 Vista、Windows 7、Windows 8 和 ZAEA23489CE3AA9B6406EBB28E0CDA43 的適當組合上進行了測試。 3.9 版本的服務器相當穩定,但始終推薦使用最新的驅動程序。 所以,應該是
browser = webdriver.Ie(executable_path=r'C:\Python27\IEDriverServer.exe')
IEDriverServer.exe 的路徑應包含在路徑中。
現在這只有在
您在中的所有 Internet 區域都有相同的保護模式設置
IE瀏覽器。 它可以打開或關閉,但必須對所有人都相同
區。
僅對於 IE11,必須存在注冊表值。 對於 32 位 Windows HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE。 對於 64 位 Windows
安裝,關鍵是
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet
Explorer\Main\FeatureControl\FEATURE_BFCACHE。 請注意,
FEATURE_BFCACHE 子鍵可能存在也可能不存在,並且應該是
如果它不存在則創建。 重要提示:在此鍵中,創建一個
名為 iexplore.exe 的 DWORD 值,值為 0。
64 位 IEDriver 服務器存在已知問題,因此建議您使用 32 位服務器,它會自動啟動 32 位 IE 瀏覽器。
所有這些要求都在這里解釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.