Search code examples
pythonseleniumgoogle-colaboratorygeckodriverfilenotfounderror

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver' using Selenium libary in Google Colab


I am trying to use Selenium in Google Colab, but i get some errors when i try to run a Firefox instance. i followed this links:

  • Selenium documentation here, i tried with the Driver Management Software but i got the error that says that was unable to find the binary location to Firefox, so i follow this other link , but i was unable to make it run

So i tried with the Hard Coded Location, but I got the error:

Message: 'geckodriver' executable needs to be in PATH.

I actually downloaded the geckodrive and follow this link

I've uploaded the grecodriver to my Drive and access with the google.colab library, but i always got the error:

No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver'

Here is my code:

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from google.colab import drive

drive.mount('/content/drive', force_remount=True)

service = FirefoxService(executable_path= '/content/drive/MyDrive/Santillana/geckodriver')
driver = webdriver.Firefox(service=service)

My drive´s files

The entire error:

---------------------------------------------------------------------------

FileNotFoundError                         Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stdin=PIPE,
---> 76                                             creationflags=self.creationflags)
     77         except TypeError:

4 frames

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver': '/content/drive/MyDrive/Santillana/geckodriver'


During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)

/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 


Solution

  • This error message...

    FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Santillana/geckodriver': '/content/drive/MyDrive/Santillana/geckodriver'
    

    ...implies that your program was unable to locate the GeckoDriver executable.


    Analysis

    As per the error message it seems you are on a system. However you have downloaded the version of GeckoDriver:

    downloaded


    Solution

    Instead of the Windows version of GeckoDriver possibly you need to download the Linux version of GeckoDriver executable.