2

My Script:

from selenium import webdriver

browser = webdriver.Chrome(executable_path='/Users/John/Desktop')

browser.get('https://www.google.com')

To execute in terminal:

python seleniumtest.py

Error:

Traceback (most recent call last):
    File "/Users/John/anaconda3/lib/python3.6/site- 
 packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/Users/John/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Users/John/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/Users/John/Desktop'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "seleniumtest.py", line 3, in <module>
    browser = webdriver.Chrome(executable_path='/Users/John/Desktop')
  File "/Users/John/anaconda3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/Users/John/anaconda3/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: 'Desktop' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I have chromedriver installed as far as I'm aware, what's going wrong here?

anon
  • 159
  • 2
  • 3
  • 9
  • 1
    Possible duplicate of [Selenium on MAC, Message: 'chromedriver' executable may have wrong permissions](https://stackoverflow.com/questions/49787327/selenium-on-mac-message-chromedriver-executable-may-have-wrong-permissions) – undetected Selenium Apr 19 '18 at 10:56
  • Your 'Desktop' is not an executable path. Edit your path to show the executable google driver. – BcK Apr 19 '18 at 11:00
  • solved it. Needed to move chromedriver executable to the local/bin. Thanks guys it works now – anon Apr 19 '18 at 11:32

2 Answers2

0

I would like to offer an alternative solution which does not require you to move chromedriver to local/bin. This was originally posted as an answer in this post. Just sharing this in case anyone stumbles upon this question when using cx_freeze on Mac.


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
0

Gonna throw another solution into the pot.

I had it like this:

import requests, json, os, time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
my_headers = {}
my_headers['user-agent'] = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'

did

brew cask install chromedriver  

and still got the error.

Then I downloaded the matching chromedriver binary at

https://chromedriver.storage.googleapis.com/index.html

and placed it in the root of my script. That seemed to do the trick!

Norfeldt
  • 8,272
  • 23
  • 96
  • 152