cannot connect to chrome at 127.0.0.1:9222


  • window10系統,先cmd打開chrome,
    chrome --remote-debugging-port=9222
  • 執行腳本
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By


def test_adduser():
    options=Options()
    options.add_experimental_option('debuggerAddress', '127.0.0.1:9222')
    driver=webdriver.Chrome(options=options)
    driver.implicitly_wait(5)
    driver.find_element(By.CSS_SELECTOR,'.js_service_list a:nth-child(1) .index_service_cnt_item_title').click()
  • 報錯
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:9222
E       from chrome not reachable

..\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: WebDriverException
  • 發現打開調試瀏覽器一段時間后,就會連不上,這是需要關閉瀏覽器,重新執行chrome --remote-debugging-port=9222
  • 再不行,重啟電腦,問題解決


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM