selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary


問題:
ft19.1: Traceback (most recent call last): File "D:\jenkins\workspace\PT4_0_UI_Script\test_case\System_Management\test_OData_permissions_update.py", line 14, in setUp driver = get_driver() File "../..\common_modules\PT4_Login.py", line 12, in get_driver driver = webdriver.Chrome() File "D:\Python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__ desired_capabilities=desired_capabilities) File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__ self.start_session(desired_capabilities, browser_profile) File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session response = self.execute(Command.NEW_SESSION, capabilities) File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "D:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}),platform=Windows NT 10.0.14393 x86_64)

解決方案:
1、瀏覽器版本和webdriver版本對應
2、瀏覽器取消自動升級功能(刪掉update文件夾下面的所有文件,設置update文件夾不允許任何操作)
3、把下載的 chromedriver.exe 復制到以下路徑
1)python 根目錄
2)D:\Python\Lib\site-packages\selenium\webdriver
3)C:\Users\Administrator\AppData\Local\Google\Chrome\Application
4)環境變量path中添加:C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver.exe
4、完成以上所有設置,新建python文件測試
代碼如下:

from selenium import webdriver
import time
option = webdriver.ChromeOptions()
option.binary_location=r'D:\Google\Chrome\Application\chrome.exe'
driver=webdriver.Chrome('C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver.exe')
driver.get("https:www.baidu.com")
time.sleep(10)
driver.quit()


免責聲明!

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



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