Search code examples
pythonwindowsseleniumfirefoxgeckodriver

OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows


I created script with selenium in Ubuntu and works just fine there, but when I moved it to windows10, I get lots of error and I tried to fix it one by one until I see this error. I've been looking for the solution to this problem but I am unable to resolve this error.

Traceback (most recent call last):
  File "D:/Users/b/Documents/Python/Bolt/GUI.py", line 180, in start
    driver = l.start_chime()  # start chime
  File "D:\Users\b\Documents\Python\Bolt\Login.py", line 87, in start_chime
    self.chime_driver = webdriver.Firefox(executable_path=self.PATH)
  File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "D:\Users\b\Documents\Python\Python3.8\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "D:\Users\b\Documents\Python\Python3.8\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  File "C:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_monkey.py", line 551, in new_CreateProcess
    return getattr(_subprocess, original_name)(app_name, patch_arg_str_win(cmd_line), *args)
OSError: [WinError 193] %1 is not a valid Win32 application

This is happen when I tried to open webdriver using selenium.

self.myday_driver = webdriver.Firefox(executable_path=self.PATH)

and is there any method to move script from Ubunto to Windows without getting error?


Solution

  • This error message...

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

    ...implies that the underlying OS doesn't recognizes %1 i.e. the system variable PATH as a valid Win32 application i.e. a executable binary.


    To initiate a Selenium driven GeckoDriver controlled Firefox session you need to:

    • Download the latest version of GeckoDriver binary version, place it in your system.

    • Next in your code block you need to mention the absolute path of the binary through the Key executable_path as follows:

      from selenium import webdriver
      
      self.myday_driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')