【发布时间】:2021-09-10 16:20:51
【问题描述】:
我之前已经多次看到这个问题提出了很好的解决方案。
事实上,我可以在从编辑器 (VS code) 运行代码时让它工作。
但是,当我创建一个批处理文件 *.bat 并尝试运行相同的文件时,我收到以下错误消息:
raise WebDriverException(selenium.common.exceptions.WebDriverException:
Message: 'chromedriver' executable needs to be in PATH. Please see
https://sites.google.com/a/chromium.org/chromedriver/home
调用代码的批处理文件如下所示:
"C:\Program Files\Python39\python.exe" "Y:\path\to\python_file.py"
exe和文件在不同的文件夹C:和Y:。
我在这里使用selenium 的常用代码:
from selenium import webdriver
PATH = r'Y:\some_path_to\chromedriver.exe'
driver = webdriver.Chrome(PATH)
我尝试过: https://sites.google.com/chromium.org/driver/getting-started
我也试过这个: Error message: "'chromedriver' executable needs to be available in the path"
我也尝试过更改 os.path: https://www.geeksforgeeks.org/python-os-chdir-method/
我进一步尝试了不同的方法和变体来让代码从批处理文件运行(同样,相同的代码从VS code 编辑器运行),但不知道如何解决错误?
额外说明: 我也尝试过改变windows环境下的路径: https://zwbetz.com/download-chromedriver-binary-and-add-to-your-path-for-automated-functional-testing/
但这不起作用。
【问题讨论】:
-
我也遇到了类似的问题,给个链接
-
这能回答你的问题吗? stackoverflow.com/questions/67901942/…
-
我已经尝试了不同的变体,但不起作用。有什么具体的建议吗?
标签: python python-3.x selenium selenium-webdriver selenium-chromedriver