首页 > 解决方案 > Python 从 selenium 启动 Chromedriver 在 IDLE 中有效,但在 Visual Studio Code 中无效

问题描述

下面是我的代码,当我通过 powershell/cmd/IDLE 运行它时,它会完美地启动 chromedriver。但是,当我尝试通过 Visual Studio 代码运行它时,我收到以下文本。

“selenium.common.exceptions.WebDriverException:消息:'chromedriver.exe' 可执行文件需要在 PATH 中。请参阅https://sites.google.com/a/chromium.org/chromedriver/home

#SELENIUM INFO#
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
#SELENIUM INFO#
import os

print(os.getcwd())

driver = webdriver.Chrome(os.getcwd() +'\\chromedriver.exe')

我右键单击代码并单击“在终端中运行 Python 文件”但是我发现我什至无法使用终端来 cd 到文件结构内部更深的代码。

我的文件结构是“G:\Quality User Data\Malahy\Projects\AQE Interfaces>”

但是chrome驱动和python文件一起存放在更深的目录中。

"G:\Quality User Data\Malahy\Projects\AQE Interfaces\AQE Interface\Logistics\Repack"

我开始认为这是 Visual Studio Code 的错误,而不是我的程序。

标签: pythonseleniumselenium-chromedriveros.path

解决方案


推荐阅读