繁体   English   中英

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

[英]Python Selenium test: [WinError 193] %1 is not a valid Win32 application

操作系统: Win10
Python: venv 3.8
铬: 95.0.4638.69
Chrome 驱动程序: 95.0.4638.69
硒: 4.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"libs\chromedriver.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:\Projects\tests\smoke_tests.py", line 13, in setUpClass
    self.driver = webdriver.Chrome(service=ser)
  File "C:\Projects\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Projects\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
    self.service.start()
  File "C:\Projects\venv\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Python38\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python38\lib\subprocess.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修复了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM