首页 > 解决方案 > OSError: [WinError 193] %1 在通过 Selenium ChromeDriver 和 Python 中的 Chrome 进行自动化时不是有效的 Win32 应用程序

问题描述

代码块:

import time
from selenium import webdriver

browser = webdriver.Chrome('C:/Users/Cypher/Downloads/chromedriver_win32.zip')
browser.maximize_window()
browser.get('https://www.google.com/gmail/')
email_field = browser.find_element_by_id('identifierId')
email_field.clear()
email_field.send_keys('My mail')
email_next_button = browser.find_element_by_id('identifierNext')
email_next_button.click()
time.sleep(1)
password_field = browser.find_element_by_name('password')
password_field.clear()
password_field.send_keys('My password')
password_next_button = browser.find_element_by_id('passwordNext')
password_next_button.click()
time.sleep(100)
browser.quit()

错误:

Traceback (most recent call last):
  File "C:/Users/Cypher/PycharmProjects/untitled5/login_gmail.py", line 4, in <module>
    driver = webdriver.Chrome('C:/Users/Cypher/Downloads/chromedriver_win32.zip')
  File "C:\Users\Cypher\PycharmProjects\untitled5\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Cypher\PycharmProjects\untitled5\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\Cypher\Miniconda3\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Cypher\Miniconda3\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application

标签: pythonseleniumgoogle-chromeselenium-webdriverselenium-chromedriver

解决方案


只需提取您下载的 chromedriver...chromedriver_win32.zip确保您chromedriver.exe在下载中包含该文件...

browser = webdriver.Chrome('C:/Users/Cypher/Downloads/chromedriver.exe')

希望这对你有帮助!


推荐阅读