【问题标题】:Selenium WebDriver commenSelenium WebDriver 常见
【发布时间】:2022-07-25 18:22:40
【问题描述】:

这是python代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import subprocess

EXTENSION_PATH = "C:/Users/HP/AppData/Local/Google/Chrome/User Data/Default/Extensions/nkbihfbeogaeaoehlefnkodbefgpgknn/10.17.0_0.crx" 

opt = webdriver.ChromeOptions()
opt.add_extension(EXTENSION_PATH)
driver = webdriver.Chrome(chrome_options=opt)
time.sleep(1)

我尝试运行程序时出现以下错误:(文件名:1.py)

"C:/Program Files/Python310/python.exe" c:/Users/HP/Desktop/py/1.py
c:\Users\HP\Desktop\py\1.py:27: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options=opt)
Traceback (most recent call last):
  File "C:\Users\HP\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\common\service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Program Files\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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\HP\Desktop\py\1.py", line 27, in <module>
    driver = webdriver.Chrome(chrome_options=opt)
  File "C:\Users\HP\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\HP\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
    self.service.start()
  File "C:\Users\HP\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

我将所有需要的文件都放在了补丁中。 我正在使用窗户

【问题讨论】:

  • 尝试将位置显式设置为 chromedriver.exe webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")

标签: python selenium webdriver


【解决方案1】:

变化:

driver = webdriver.Chrome(chrome_options=opt)

与:

driver = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe", options=opt)

你应该很高兴。

【讨论】:

  • opt = webdriver.ChromeOptions() opt.add_extension(EXTENSION_PATH) driver = webdriver.Chrome(options=opt) time.sleep(1)
猜你喜欢
  • 1970-01-01
  • 2015-05-03
  • 2018-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-25
  • 2018-09-08
  • 2015-07-19
相关资源
最近更新 更多