简体   繁体   English

“未定义驱动程序” Python / Selenium

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

I want to use Selenium on Python but I have an alert message: 我想在Python上使用Selenium,但有一条警告消息:

driver-webdriver.Chrome("D:\\Selenium\\Chrome\\chromedriver.exe") NameError: name 'driver' is not defined driver-webdriver.Chrome(“ D:\\ Selenium \\ Chrome \\ chromedriver.exe”)NameError:名称“ driver”未定义

I have installed the Chrome Driver, what else must I do ? 我已经安装了Chrome驱动程序,该怎么办?

chromedriver.exe must be in python path, probably now python expects that driver exists in "D:\\Selenium\\Chrome\\chromedriver.exe" but it does not. chromedriver.exe必须位于python路径中,可能现在python希望该驱动程序存在于“ D:\\ Selenium \\ Chrome \\ chromedriver.exe”中,但不存在。 You could try add chromedriver.exe path to windows enviroment path variable, or add path to os.path in python, or add driver to folder of python script. 您可以尝试将chromedriver.exe路径添加到Windows环境路径变量,或在python中将路径添加到os.path,或将驱动程序添加到python脚本的文件夹。

driver = webdriver.Chrome(path_to_your_chromedriver.exe)

If chromedriver is in your PATH you dont have to specify. 如果chromedriver在您的PATH中,则无需指定。 Remember to use double slashes - or put an r in front of the chromedriver path 记住要使用双斜杠-或在chromedriver路径的前面放一个r

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

Here is the Answer to your Question: 这是您的问题的答案:

While working with Selenium 3.4.3, chromedriver v2.30 and Google Chrome v59.0 through Python 3.6.1 you neither need to install chromedriver nor need to copy in to any path . 在通过Python 3.6.1使用Selenium 3.4.3, chromedriver v2.30和Google Chrome v59.0时,您既不需要安装chromedriver也无需复制到任何path You can save the chromedriver in any location on your machine. 您可以将chromedriver保存在chromedriver上的任何位置。 To initiate the WebDriver instance you can explicitly call the chromedriver by passing the absolute path of the chromedriver through the argument executable_path as follows: 要启动webdriver的情况下,你可以显式调用chromedriver通过传递的绝对路径chromedriver通过参数executable_path如下:

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

Let me know if this Answers your Question. 让我知道这是否回答了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM