16

I'm just trying to do something very basic on my Mac using selenium and I can't even open a webpage. I'm getting an error of :

Traceback (most recent call last):
  File "/Users/godsinred/Desktop/InstagramLiker/GmailAccountGenerator.py", line 10, in <module>
    driver = webdriver.Chrome()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 88, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Here is my code below:

from selenium import webdriver
import time

link = "https://accounts.google.com"
driver = webdriver.Chrome()
driver.get(link)
time.sleep(5)

driver.quit()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jonathan Ishii
  • 379
  • 2
  • 4
  • 12

6 Answers6

19

Most answers here and in other related posts suggest users to just move the file to /usr/bin and they work fine if you are just running chromedriver locally and normally.

However, if you are compiling Python scripts into executables using compilers such as cx_freeze, you may not be able to afford the luxury if your program always uses a relative link to chromedriver.

As the error message suggests, your compiled program does not have the permissions to manipulate chromedriver. To use a relative link to chromedriver on a Mac in your compiled Python program, you can programmatically change the permission of chromedriver in your Python script using:

import os
os.chmod('/path/to/chromedriver', 0755) # e.g. os.chmod('/Users/user/Documents/my_project/chromedriver', 0755)

You can test this by doing the following:

  1. cd to your working directory

  2. $ chmod 755 chromedriver to allow your program to manipulate it

P.S. 755 is the default numerical permission for files in usr/bin. 664 is the default numerical permission for files in other normal folders (probably your working directory). Thus, when chromedriver complains it does not have the correct permission, you need to grant it a numerical permission equivalent to or greater than 755.

user5305519
  • 3,008
  • 4
  • 26
  • 44
6

The error says it all :

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

The error clearly mentions that the chromedriver which is getting detected have wrong permissions.


Solution

  • Download the latest chromedriver binary from ChromeDriver - WebDriver for Chrome and save it in your system.
  • Ensure that chromedriver binary have the required permissions.
  • While initiating the WebDriver and WebClient pass the argument executable_path along with the absolute path of the chromedriver binary as follows :

    from selenium import webdriver
    
    link = "https://accounts.google.com"
    driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
    driver.get(link)
    

Reference

You can find a detailed relevant discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you so much it worked out. I also forgot to add it to my paths. executed sudo paths /etc/paths/ in the terminal and added the chrome driver to the paths directory – Jonathan Ishii Apr 15 '18 at 08:14
1

If you are on windows give path including file name. For example, './chromedriver/chromedriver.exe' My line of code looks like below.

service = webdriver.chrome.service.Service('./chromedriver/chromedriver.exe')

0

This worked! I followed these instructions to update PATH: https://www.kenst.com/2015/03/installing-chromedriver-on-mac-osx/

I dragged my chromedriver.exe from Finder into Terminal (/etc/paths), and then copied the address in Terminal and dropped it into my Python IDE where the PATH should be inserted.

meng1313
  • 9
  • 1
  • 1
    Welcome to Stack Overflow! While links are great way of sharing knowledge, they won't really answer the question if they get broken in the future. Add to your answer the essential content of the link which answers the question. In case the content is too complex or too big to fit here, describe the general idea of the proposed solution. Remember to always keep a link reference to the original solution's website. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – sɐunıɔןɐqɐp Sep 23 '18 at 12:02
0

Check out a this topics

1- If you are using Linux, access the folder containing the file Chromedriver.exe set on 755

2- check correct path for Chromedriver.exe file in your code

3- If you are using Windows servers,check the Chromedriver.exe file is available for the current user (not only the admin does have access to Chromedriver.exe - see in c://users...)

mamal
  • 1,791
  • 20
  • 14
0

What worked for me in Windows was adding the location of the driver to Windows local PATH var, restarting my python environment so that the path to the driver displayed after running this:

import os;path = os.getenv('PATH'); print(path);

and then I did not specify the path when loading the driver:

from selenium import webdriver
driver =  webdriver.Chrome()

if I tried putting the path in the Chrome() call it caused the permissions error. Adding it to the local environment path is enough.

EliSquared
  • 1,409
  • 5
  • 20
  • 44