Chlenmedriver for selenium PermissionError:[Errno 1]操作不允许在Mac OSx上出错

时间:2018-01-02 22:34:56

标签: python macos selenium

我有以下python代码

import time
from selenium import webdriver

driver = webdriver.Chrome('/Users/xxxx/Downloads/chromedriver')  
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()

当我执行这个python脚本时,我得到了异常:

Traceback (most recent call last):
  File "/var/folders/0m/p0pyygms6g9_bqlfb9bmg0w80000gn/T/PythonRunner/dummy.py", line 4, in <module>
    driver = webdriver.Chrome('/Users/xxxx/Downloads/chromedriver')  # Optional argument, if not specified will search path.
  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 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 1] Operation not permitted: '/Users/xxxx/Downloads/chromedriver'

我已尝试将chromedrive Linux可执行文件的更改权限更改为777并重新安装selenium但出现同样的错误

我在解决此问题时需要帮助。请告诉我。

2 个答案:

答案 0 :(得分:1)

错误说明如下:

driver = webdriver.Chrome('/Users/xxxx/Downloads/chromedriver')  # Optional argument, if not specified will search path.

您必须通过键值对提及 chromedriver 二进制文件的绝对路径,如下所示:

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/Users/xxxx/Downloads/chromedriver')  
driver.get('http://www.google.com');

答案 1 :(得分:0)

您可以尝试将webdriver移动到/ usr / local / bin

import time
from selenium import webdriver

driver = webdriver.Chrome()  
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()