Python Selenium测试:[WinError 193]%1不是有效的Win32应用程序



OS:Win10
Python:venv3.8
铬:95.0.4638.69
铬驱动程序:95.0.4638.39
硒:14.0.0

尝试运行简单的测试:

import os
import unittest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

class SmokeTests(unittest.TestCase):
@classmethod
def setUpClass(self):
chromedriver_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r"libschromedriver.exe")
ser = Service(chromedriver_path)
self.driver = webdriver.Chrome(service=ser)
base_url = 'https://google.com/'
self.driver.get(base_url)
@classmethod
def tearDownClass(self):
self.driver.quit()
def test_name_in_tab_title(self):
expected_tab_title = 'Google'
observed_tab_title = self.driver.title
self.assertEqual(expected_tab_title, observed_tab_title)

测试在前一天开始,当我再次启动我的机器时,我出现了错误:

----------------------------------------------------------------------
Traceback (most recent call last):
File "C:Projectstestssmoke_tests.py", line 13, in setUpClass
self.driver = webdriver.Chrome(service=ser)
File "C:Projectsvenvlibsite-packagesseleniumwebdriverchromewebdriver.py", line 69, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:Projectsvenvlibsite-packagesseleniumwebdriverchromiumwebdriver.py", line 90, in __init__
self.service.start()
File "C:Projectsvenvlibsite-packagesseleniumwebdrivercommonservice.py", line 74, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:Python38libsubprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:Python38libsubprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
----------------------------------------------------------------------
Ran 0 tests in 0.003s
FAILED (errors=1)

普通Python代码执行正常。

删除并再次添加chromedriver.exe修复了问题。

相关内容

  • 没有找到相关文章

最新更新