[英]OSError: [WinError 193] %1 is not a valid Win32 application while automating through Selenium ChromeDriver and Chrome in Python
[英]Python Chromedriver WinError 2 with Selenium
我的代码中出现以下错误:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py",
line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
我尝试更改 PATH 变量,更改 chromedriver 路径无济于事。 有趣的是,这个错误只是偶尔发生,但我还没有找到一个模式。 这是我的 chromedriver 定义:
options = Options()
options.headless = True
options.add_argument('--log-level=3')
chromepath = str(Path(os.getcwd()).parent) + r'\chromedriver.exe'
driver = webdriver.Chrome(chromepath, options=options)
奇怪的是它有时只起作用。 将此设置为绝对路径,它应该可以正常工作。
chromepath = str(Path(os.getcwd()).parent) + r'\chromedriver.exe'
print (chromepath) #set the output of this below
driver = webdriver.Chrome("abs path here", options=options)
更新:解决方案。 结果我定义了两次驱动程序,删除了一个定义,它似乎做得很好。 不确定为什么它会引发该特定错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.