簡體   English   中英

“未定義驅動程序” Python / Selenium

[英]“Driver is not defined” Python/Selenium

我想在Python上使用Selenium,但有一條警告消息:

driver-webdriver.Chrome(“ D:\\ Selenium \\ Chrome \\ chromedriver.exe”)NameError:名稱“ driver”未定義

我已經安裝了Chrome驅動程序,該怎么辦?

chromedriver.exe必須位於python路徑中,可能現在python希望該驅動程序存在於“ D:\\ Selenium \\ Chrome \\ chromedriver.exe”中,但不存在。 您可以嘗試將chromedriver.exe路徑添加到Windows環境路徑變量,或在python中將路徑添加到os.path,或將驅動程序添加到python腳本的文件夾。

driver = webdriver.Chrome(path_to_your_chromedriver.exe)

如果chromedriver在您的PATH中,則無需指定。 記住要使用雙斜杠-或在chromedriver路徑的前面放一個r

... = webdriver.Chrome(r'path_without_doubble_slashes)

這是您的問題的答案:

在通過Python 3.6.1使用Selenium 3.4.3, chromedriver v2.30和Google Chrome v59.0時,您既不需要安裝chromedriver也無需復制到任何path 您可以將chromedriver保存在chromedriver上的任何位置。 要啟動webdriver的情況下,你可以顯式調用chromedriver通過傳遞的絕對路徑chromedriver通過參數executable_path如下:

from selenium import webdriver
driver = webdriver.Chrome(executable_path= r'C:\\Utility\\BrowserDrivers\\chromedriver.exe')

讓我知道這是否回答了您的問題。

錯誤

[英]Python TKinter, Selenium and threading throwing driver not defined error

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM