-1

I have been using Google Colab for my python projects. I want to learn & implement Selenium using Google Colab. I am trying to log in to Facebook as shown below. But, I am stuck with 'Permission error'. I have looked into various posts & tried to execute suggested solutions such as (Selenium on MAC, Message: 'chromedriver' executable may have wrong permissions) but did not help.

What I've tried.

  1. Referred https://sites.google.com/a/chromium.org/chromedriver/home article as suggested
  2. Used chmod 755 to allow executable permissions
  3. Referenced 'chromedriver.exe' in different folders within Colab environment and but no luck

The Code:

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

user_name = 'Username'
password = 'Password'

os.chmod('/content/chromedriver.exe', 755)
driver = webdriver.Chrome(executable_path='/content/')
driver.get("https://www.facebook.com")

element = driver.find_element_by_id("email")
element.send_keys(user_name)

element = driver.find_element_by_id("pass")
element.send_keys(password)

element.send_keys(Keys.RETURN)

driver.close()

Complete error:

---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stderr=self.log_file,
---> 76                                             stdin=PIPE)
     77         except TypeError:

4 frames
PermissionError: [Errno 13] Permission denied: '/content/'

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     86                 raise WebDriverException(
     87                     "'%s' executable may have wrong permissions. %s" % (
---> 88                         os.path.basename(self.path), self.start_error_message)
     89                 )
     90             else:

WebDriverException: Message: '' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Snapshot of my Colab Environment

enter image description here

Can someone please help me fix this issue?

PS: The same code works using Jupyter Notebook, Eclipse IDE. But on the long run, I want to remove my dependence on Jupyter Notebooks & rely on Cloud based Notebook environment such as Google Colab which in theory should allow me to focus on code rather than troubleshooting libraries/compatibility/permission/etc issues.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bharath
  • 117
  • 1
  • 2
  • 8

2 Answers2

2

This error message...

PermissionError: [Errno 13] Permission denied: '/content/'
.
WebDriverException: Message: '' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

...implies that the WebDriver exexutable wasn't detected and hence Selenium suspects that the executable may have wrong permissions.


Solution

While passing the Key executable_path you need to pass the absolute path of the WebDriver variant name, i.e. chromedriver as follows:

driver = webdriver.Chrome(executable_path='/content/chromedriver')
                          webdriver variant name ^^^chromedriver^^^ needs to be appended

References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

You can also get this error (and it can be one of those things that is so obvious you don't notice it) if you unpack the package into a directory with the same name as the executable

In other words, it looks like you've unpacked /content/chromedriver - but the path to the executable is /content/chromedriver/chromedriver - so even if you set permissions on the path and pass the path in with executable_path you still get an error 13.

Just adding it to the thread as it threw me off and the error wasn't obvious at first.

Allan Elder
  • 4,052
  • 17
  • 19