I trying to run an Python file today and got this error below! Anyone know what's issue and the solution to fix it?
Traceback (most recent call last):
File "C:\Users\Al PC\PycharmProjects\Fe\report_auto-final-v2.7.py", line 60, in <module>
driver = webdriver.Chrome(service=chrome_service, options=options) # ChromeDriverManager()
File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
super().__init__(
File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 53, in __init__
self.service.start()
File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\common\service.py", line 105, in start
self._start_process(self._path)
File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\common\service.py", line 206, in _start_process
self.process = subprocess.Popen(
File "C:\Users\Al PC\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Al PC\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
Process finished with exit code 1
If you construct the service like this:
service = ChromeService(ChromeDriverManager().install())
I noticed ChromeDriverManager().install()
returns <path stuff>\chromedriver-win32\THIRD_PARTY_NOTICES.chromedriver
instead of the chromedrive.exe
.
This works for me:
chrome_install = ChromeDriverManager().install()
folder = os.path.dirname(chrome_install)
chromedriver_path = os.path.join(folder, "chromedriver.exe")
service = ChromeService(chromedriver_path)