3

I am using Google Chrome version 83.0.4103.116 and ChromeDriver 83.0.4103.39. I am trying to use chrome driver in google colab. I use the path of chromedriver after uploading it in google colab. Could you please point out where i m getting error. This is the code

import selenium
from selenium import webdriver
wd = webdriver.Chrome(r'/content/chromedriver.exe')

This is the 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/chromedriver.exe'

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: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

2

Google Colaboratory

Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud which enables us to write and execute code, save and share your analyses, and access powerful computing resources, all for free from your browser.

The entire colab runs in a cloud VM. If you investigate the VM you will find that the current colab notebook is running on top of Ubuntu 18.04.3 LTS.

So while using Selenium instead of mentioning the WebDriver variant along with the extension i.e. .exe you need to drop the extension. So effectively your code block will be:

import selenium
from selenium import webdriver
wd = webdriver.Chrome('/content/chromedriver')

Update

Incase you aren't sure where the ChromeDriver is getting downloaded you can move it to a known location and use it as follows:

!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium

from selenium import webdriver
wd = webdriver.Chrome('/usr/bin/chromedriver')

References

You can find a couple of detailed relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • While trying to run without exe then it gives this error WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home – Soudip Karmakar Jul 02 '20 at 13:55
  • '/content/chromedriver.exe' is the path i got after uploding chromedrive file in the google colab – Soudip Karmakar Jul 02 '20 at 13:56
  • @SoudipKarmakar That sounds to be a different issue completely. Can you raise a new question as per yournew requirement please? – undetected Selenium Jul 02 '20 at 14:00
  • wd = webdriver.Chrome(r'/content/chromedriver.exe' )that what I am talking. After uploading the chromedriver file in the google colab, '/content/chromedriver.exe' is the path of the uploaded file.There is no error from the path. But while i m using this-wd=webdriver.Chrome('/content/chromedriver') then i get this error-While trying to run without exe then it gives this error WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see sites.google.com/a/chromium.org/chromedriver/home – Soudip Karmakar Jul 02 '20 at 15:45
  • @SoudipKarmakar Checkout the updated answer and let me know the status. – undetected Selenium Jul 03 '20 at 06:41
  • Yes it is working. But at the end this error comes :MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=43465): Max retries exceeded with url: /session/97f397fa9f8f046a5b44bf75808d09c6/url (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',)). I am not able to sort out the solution from there https://stackoverflow.com/questions/62703937/http-connection-pool-error-failed-to-establish-a-new-connection?noredirect=1#comment110895056_62703937 – Soudip Karmakar Jul 03 '20 at 07:16
  • @SoudipKarmakar Again, `MaxRetryError: HTTPConnectionPool()` is a different error and you need to address it differently. – undetected Selenium Jul 03 '20 at 07:21
  • yes i m asking in different question. This is the link: https://stackoverflow.com/questions/62703937/http-connection-pool-error-failed-to-establish-a-new-connection – Soudip Karmakar Jul 03 '20 at 07:32
0

I made a library to help using selenium in Colab easier.

You can just call this

!pip install kora -q
from kora.selenium import wd
wd.get(url)
korakot
  • 37,818
  • 16
  • 123
  • 144
  • After executing this from kora.selenium import wd i get this error.WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -6 – Soudip Karmakar Jul 02 '20 at 16:18
  • Try start it in a new notebook. It might interfere with our previous chromedriver. – korakot Jul 02 '20 at 17:25
  • I m starting in new notebook. wd.get('https://google.com') after this line i get this error:MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=44451): Max retries exceeded with url: /session/d653bd20a28ef757c930aba4d7283777/url (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',)) – Soudip Karmakar Jul 02 '20 at 18:48
  • I think it is okay. Due to some other function it might happen. – Soudip Karmakar Jul 02 '20 at 19:31
  • https://stackoverflow.com/questions/62703937/http-connection-pool-error-failed-to-establish-a-new-connection Could you please check once the problem. I am posting the whole code over there and the error what i have got. – Soudip Karmakar Jul 02 '20 at 19:44