我安装了selenium并下载了chromedriver.exe 当我在 gitbash 终端中运行代码时,它可以工作,但当我在 Visual Studio 代码中运行 python 脚本时,它不起作用。
在互联网上,它说将文件放在路径中,但我对此不太了解。我应该把 chromedriver.exe 放在哪里?
最佳答案
简单的答案是任何地方。
通过命令行添加放置驱动程序的路径:
set PATH=%PATH%;C:\WHERE_I_PUT_THEDRIVER\
或者
在控制面板 -> 所有控制面板项 -> 系统 -> 高级系统设置 -> 高级 -> 环境变量 -> 系统变量 -> [选择] 路径 -> [单击] 编辑
所以当你导入它时。
from selenium import webdriver
wd = webdriver.Chrome()
或者,如果您不想添加新路径,
from selenium import webdriver
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
#__location__ is current file location
driver_loca = os.path.join(__location__, 'bin/chromedriver.exe')
wd = webdriver.Chrome(executable_path= driver_loca)
关于python - 在Python中通过selenium执行测试时,ChromeDriver应该放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52111479/