![](/img/trans.png)
[英]selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service error using ChromeDriver Chrome through Selenium Python
[英]selenium.common.exceptions.WebDriverException: Message: disconnected: received Inspector.detached event with ChromeDriver and Selenium through Python
我遇到錯誤
E
======================================================================
ERROR: test_01Login (__main__.LoginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:/Users/amal/AppData/Local/Continuum/anaconda3/Lib/site-packages/Sucess/Test/Login_sj.py", line 29, in test_01Login
driver.get("https://google.com")
File "C:\Users\amal\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\amal\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\amal\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: disconnected: received Inspector.detached event
(Session info: chrome=76.0.3809.100)
----------------------------------------------------------------------
Ran 1 test in 8.615s
FAILED (errors=1)
嘗試使用python 3.7和selenium 3.141.0自動化網頁時
這是在Windows 10中。我的Java版本是jdk-12.0.2,Chrome驅動程序是ChromeDriver 76.0.3809.68
driver = webdriver.Chrome()
driver.get("https://google.com")
我是自動化的新手,通過反復試驗和任何錯誤的借口學習,因為我剛剛創建了此帳戶並嘗試在任何論壇中首次發布。 我嘗試重新安裝Java,Chrome,並嘗試了多個版本的chromedriver。 任何幫助將非常感激。
此錯誤消息...
WebDriverException: Message: disconnected: received Inspector.detached event
...表示您嘗試打開DevTools窗口時, ChromeDriver已自動斷開連接。
根據文章文章,如果您嘗試在ChromeDriver忙於執行自動化測試時打開DevTools窗口,則DevTools窗口會一直關閉 , ChromeDriver會自動斷開連接,並且當ChromeDriver收到處於斷開狀態的命令時,它將嘗試關閉DevTools窗口並重新連接背部。 較早的Chrome的DevTools每頁只允許一個調試器。 但是從ChromeDriver v2.x開始,它現在已成為DevTools調試客戶端。
如果您需要通過DevTools檢查DOM樹 ,最好的方法是暫停測試執行,以使ChromeDriver不會關閉DevTools。 通過Chrome檢查完HTML DOM后 ,您可以取消暫停測試,ChromeDriver將關閉該窗口並繼續。
根據有關未知錯誤的討論:無法確定斷開連接的加載狀態:收到Inspector.detached將ChromeDriver放置在路徑中即可解決此問題。 因此,您需要:
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
driver.get("https://google.com")
PS:確保您使用的是最新的ChromeDriver v76.0和Chrome v76.0 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.