Problem: I made a code in python using selenium in pycharm and used it for few days untill I get this error and I scraped all the solution in the internet possible but no luck with that I so I was forces to write my first question to get solution in Stack overflow. Remember Code worked for few days then it give the error.
Note I am a beginner in python and selenium My code is huge so I will give the part where it gives the error and the setting of the code before running the webdriver
from selenium import webdriver
from selenium.webdriver.edge.options import Options
# from selenium.webdriver.common.keys import Key
from time import sleep
from selenium.webdriver.support.select import Select
options = Options()
options = webdriver.EdgeOptions()
options.add_experimental_option("detach", True)
options.add_argument(r"user-data-dir=C:\Users\reals\AppData\Local\Microsoft\Edge\User Data")
options.add_argument("profile-directory=Profile 1")
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
options.add_extension(r"C:\Users\reals\Downloads\Compressed\ABS-20230126T194006Z-001\ABS.crx")
# create a new Edge driver instance
driver = webdriver.Edge(options=options)
Error :
In above code we have error in this line
driver = webdriver.Edge(options=options)
Full error message
Traceback (most recent call last):
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 195, in _start_process
self.process = subprocess.Popen(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
self._start_process(self.path)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 209, in _start_process
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'msedgedriver' executable needs to be in PATH. Please download from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\reals\PycharmProjects\pythonProject1\jade.py", line 17, in <module>
driver = webdriver.Edge(options=options)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 73, in __init__
super().__init__(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 101, in __init__
self.service.start()
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 100, in start
self._start_process(path)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 195, in _start_process
self.process = subprocess.Popen(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
Response Time I will try to response ASAP in few hours. Everyone's help is appreciated
I tried re installing every thing from python to pycharm. I tried using pythonx32 bit version but no luck. I tried to use everything outside the code because people explains this error is because somethings is mismatching with your 64 and 32 bit systems but I haven't tried anything with the code so I am open to do anything to fix this error.
Seems like you're missing msedgedriver.exe
.
You can download it on Microsoft and then specify the path with:
from selenium import webdriver
from selenium.webdriver.edge.service import Service
ser = Service("path_to_driver\msedgedriver.exe")
options = webdriver.EdgeOptions()
options.add_experimental_option("detach", True)
options.add_argument(r"user-data-dir=C:\Users\reals\AppData\Local\Microsoft\Edge\User Data")
options.add_argument("profile-directory=Profile 1")
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
options.add_extension(r"C:\Users\reals\Downloads\Compressed\ABS-20230126T194006Z-001\ABS.crx")
driver = webdriver.Edge(service = ser,options = options )