Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webdriver-manager with error on Chrome #668

Open
AlineGobbi opened this issue Jul 30, 2024 · 3 comments
Open

webdriver-manager with error on Chrome #668

AlineGobbi opened this issue Jul 30, 2024 · 3 comments

Comments

@AlineGobbi
Copy link

import pandas as pd
import mysql.connector
from bs4 import BeautifulSoup
from time import sleep
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
servico = Service(ChromeDriverManager().install())
navegador = webdriver.Chrome(service=servico)

OSError: [WinError 193] %1 não é um aplicativo Win32 válido

@AlineGobbi AlineGobbi changed the title webdriver-manager with error webdriver-manager with error on Chrome Jul 30, 2024
@adi-prasetyo
Copy link

I've also encountered similar problem

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
driver.get('https://test.com/Login/')
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File d:\PycharmProjects\master_db_updater\open_inforex.py:2
      [1](file:///D:/PycharmProjects/master_db_updater/open_inforex.py:1) # %%
----> [2](file:///D:/PycharmProjects/master_db_updater/open_inforex.py:2) driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
      [3](file:///D:/PycharmProjects/master_db_updater/open_inforex.py:3) driver.get('https://test.com/Login')
      [5](file:///D:/PycharmProjects/master_db_updater/open_inforex.py:5) # Wait for the page to load

File d:\PycharmProjects\master_db_updater\.venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py:45, in WebDriver.__init__(self, options, service, keep_alive)
     [42](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:42) service = service if service else Service()
     [43](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:43) options = options if options else Options()
---> [45](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:45) super().__init__(
     [46](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:46)     browser_name=DesiredCapabilities.CHROME["browserName"],
     [47](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:47)     vendor_prefix="goog",
     [48](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:48)     options=options,
     [49](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:49)     service=service,
     [50](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:50)     keep_alive=keep_alive,
     [51](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chrome/webdriver.py:51) )

File d:\PycharmProjects\master_db_updater\.venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py:55, in ChromiumDriver.__init__(self, browser_name, vendor_prefix, options, service, keep_alive)
     [52](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:52)     options.browser_version = None
     [54](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:54) self.service.path = finder.get_driver_path()
---> [55](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:55) self.service.start()
     [57](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:57) executor = ChromiumRemoteConnection(
     [58](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:58)     remote_server_addr=self.service.service_url,
     [59](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:59)     browser_name=browser_name,
   (...)
     [62](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:62)     ignore_proxy=options._ignore_local_proxy,
     [63](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:63) )
     [65](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/chromium/webdriver.py:65) try:

File d:\PycharmProjects\master_db_updater\.venv\Lib\site-packages\selenium\webdriver\common\service.py:98, in Service.start(self)
     [91](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:91) def start(self) -> None:
     [92](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:92)     """Starts the Service.
     [93](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:93) 
     [94](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:94)     :Exceptions:
     [95](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:95)      - WebDriverException : Raised either when it can't start the service
     [96](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:96)        or when it can't connect to the service
     [97](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:97)     """
---> [98](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:98)     self._start_process(self._path)
    [100](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:100)     count = 0
    [101](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:101)     while True:

File d:\PycharmProjects\master_db_updater\.venv\Lib\site-packages\selenium\webdriver\common\service.py:208, in Service._start_process(self, path)
    [205](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:205)         start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
    [206](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:206)         start_info.wShowWindow = subprocess.SW_HIDE
--> [208](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:208)     self.process = subprocess.Popen(
    [209](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:209)         cmd,
    [210](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:210)         env=self.env,
    [211](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:211)         close_fds=close_file_descriptors,
    [212](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:212)         stdout=self.log_output,
    [213](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:213)         stderr=self.log_output,
    [214](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:214)         stdin=PIPE,
    [215](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:215)         creationflags=self.creation_flags,
    [216](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:216)         startupinfo=start_info,
    [217](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:217)         **self.popen_kw,
    [218](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:218)     )
    [219](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:219)     logger.debug(
    [220](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:220)         "Started executable: `%s` in a child process with pid: %s using %s to output %s",
    [221](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:221)         self._path,
   (...)
    [224](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:224)         self.log_output,
    [225](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:225)     )
    [226](file:///D:/PycharmProjects/master_db_updater/.venv/Lib/site-packages/selenium/webdriver/common/service.py:226) except TypeError:

File ~\AppData\Local\Programs\Python\Python311\Lib\subprocess.py:1026, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
   [1022](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1022)         if self.text_mode:
   [1023](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1023)             self.stderr = io.TextIOWrapper(self.stderr,
   [1024](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1024)                     encoding=encoding, errors=errors)
-> [1026](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1026)     self._execute_child(args, executable, preexec_fn, close_fds,
   [1027](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1027)                         pass_fds, cwd, env,
   [1028](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1028)                         startupinfo, creationflags, shell,
   [1029](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1029)                         p2cread, p2cwrite,
   [1030](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1030)                         c2pread, c2pwrite,
   [1031](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1031)                         errread, errwrite,
   [1032](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1032)                         restore_signals,
   [1033](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1033)                         gid, gids, uid, umask,
   [1034](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1034)                         start_new_session, process_group)
   [1035](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1035) except:
   [1036](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1036)     # Cleanup if the child failed starting.
   [1037](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1037)     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~\AppData\Local\Programs\Python\Python311\Lib\subprocess.py:1538, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)
   [1536](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1536) # Start the process
   [1537](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1537) try:
-> [1538](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1538)     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   [1539](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1539)                              # no special security
   [1540](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1540)                              None, None,
   [1541](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1541)                              int(not close_fds),
   [1542](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1542)                              creationflags,
   [1543](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1543)                              env,
   [1544](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1544)                              cwd,
   [1545](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1545)                              startupinfo)
   [1546](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1546) finally:
   [1547](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1547)     # Child is launched. Close the parent's copy of those pipe
   [1548](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1548)     # handles that only the child should have open.  You need
   (...)
   [1551](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1551)     # pipe will not close when the child process exits and the
   [1552](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1552)     # ReadFile will hang.
   [1553](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1553)     self._close_pipe_fds(p2cread, p2cwrite,
   [1554](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1554)                          c2pread, c2pwrite,
   [1555](https://file+.vscode-resource.vscode-cdn.net/d%3A/PycharmProjects/master_db_updater/~/AppData/Local/Programs/Python/Python311/Lib/subprocess.py:1555)                          errread, errwrite)

OSError: [WinError 193] %1 is not a valid Win32 application

@adi-prasetyo
Copy link

Found the solution, just use this instead

driver = webdriver.Chrome()

rather than webdriver_manager. Seems selenium has now been able to auto update the driver

@cobaltautomationdev
Copy link

Automated driver management
TL;DR: Selenium Manager automatically discovers, downloads, and caches the drivers required by Selenium when these drivers are unavailable.

The primary feature of Selenium Manager is called automated driver management. Let’s consider an example to understand it. Suppose we want to driver Chrome with Selenium (see the doc about how to start a session with Selenium). Before the session begins, and when the driver is unavailable, Selenium Manager manages chromedriver for us. We use the term management for this feature (and not just download) since this process is broader and implies different steps:

Browser version discovery. Selenium Manager discovers the browser version (e.g., Chrome, Firefox, Edge) installed in the machine that executes Selenium. This step uses shell commands (e.g., google-chrome --version).
Driver version discovery. With the discovered browser version, the proper driver version is resolved. For this step, the online metadata/endpoints maintained by the browser vendors (e.g., chromedriver, geckodriver, or msedgedriver) are used.
Driver download. The driver URL is obtained with the resolved driver version; with that URL, the driver artifact is downloaded, uncompressed, and stored locally.
Driver cache. Uncompressed driver binaries are stored in a local cache folder (~/.cache/selenium). The next time the same driver is required, it will be used from there if the driver is already in the cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants