我在Ubuntu中用selenium创建了脚本,并且在那里工作正常,但是当我将其移至Windows10时,出现了很多错误,我试图一一修复它,直到看到此错误。我一直在寻找解决此问题的方法,但无法解决此错误。
Traceback (most recent call last):
File "D:/Users/b/Documents/Python/Bolt/GUI.py", line 180, in start
driver = l.start_chime() # start chime
File "D:\Users\b\Documents\Python\Bolt\Login.py", line 87, in start_chime
self.chime_driver = webdriver.Firefox(executable_path=self.PATH)
File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
File "C:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_monkey.py", line 551, in new_CreateProcess
return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
OSError: [WinError 193] %1 is not a valid Win32 application
当我尝试使用Selenium打开WebDriver时会发生这种情况。
self.myday_driver = webdriver.Firefox(executable_path=self.PATH)
并且有什么方法可以将脚本从Ubunto迁移到Windows而不会出现错误?
此错误消息...
OSError: [WinError 193] %1 is not a valid Win32 application
...表示底层OS无法识别%1
系统变量PATH
,即系统变量为有效的Win32应用程序,即可执行二进制文件。
要启动由Selenium驱动的GeckoDriver控制的Firefox会话,您需要:
下载最新版本的GeckoDriver二进制版本,并将其放入您的系统中。
接下来,在代码块中,您需要通过Key提及二进制文件的绝对路径,如下所示: executable_path
from selenium import webdriver
self.myday_driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句