浏览器 = webdriver.Chrome() 不起作用

问题描述 投票:0回答:7

我正在开始使用 python 的 Selenium 并有这个:

from selenium import webdriver
browser = webdriver.Chrome()

但是它给出了这个错误:

Traceback (most recent call last):
File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
 File "C:\Users\Bradley 
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in 
__init__
restore_signals, start_new_session)
File "C:\Users\Bradley 
Jo\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in 
_execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
  File "C:\Users\Bradley Jo\Desktop\Project\app.py", line 3, in 
 <module>
 browser = webdriver.Chrome()
  File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-
  packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
 self.service.start()
 File "C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-    
 packages\selenium\webdriver\common\service.py", line 81, in start
 os.path.basename(self.path), self.start_error_message)
 selenium.common.exceptions.WebDriverException: Message: 'chromedriver'     
 executable needs to be in PATH. Please see     
 https://sites.google.com/a/chromium.org/chromedriver/home

[Finished in 1.0s]

有人知道如何解决这个问题吗?谢谢

python selenium
7个回答
3
投票

对于窗户:

  1. 检查您是否安装了最新版本的chrome浏览器
  2. 如果没有,请安装最新版本的chrome
  3. 此处
  4. 下载最新(或适当)版本的 chromedriver
  5. chromedriver.exe
    文件粘贴到
    "<Install Dir>/Python27/Scripts"
    文件夹中。

下面的代码现在应该可以工作了:

    from selenium import webdriver
    driver = webdriver.Chrome()

1
投票

从错误信息来看:

'chromedriver' executable needs to be in PATH.

很明显,你需要在

webdriver.Chrome

中传递Chrome web driver的路径
driver_path = "/Users/amit/Downloads/chromedriver"
driver = webdriver.Chrome(driver_path)

1
投票

您只需在下面的命令中传递

Chromedriver.exe
的路径即可

from selenium import webdriver

webdriver.Chrome(Chromedriver.exe's path)

然后就开始工作了


0
投票

我的猜测是问题来自于包含空格的路径(“Bradley Jo”):

C:\Users\Bradley Jo\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py

您可以尝试将网络驱动程序放在其他地方。


0
投票

错误说明如下:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

您需要覆盖任何其他现有路径,并在初始化

chromedriver
实例时将
webdriver
二进制文件的绝对路径作为参数传递,如下所示:

from selenium import webdriver

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

0
投票

您可以尝试将 chromedriver 放在与您的程序相同的文件夹中。这对我有用。那么Python文档中的这段代码就足够了。

from selenium import webdriver
driver = webdriver.Chrome()

0
投票

我制作了一个关于运行 chromedriver 和 selenium 的专门视频。在这里查看:https://www.youtube.com/watch?v=siphI_6RjQ0

© www.soinside.com 2019 - 2024. All rights reserved.