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

问题描述 投票:0回答:2

我有以下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'

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

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

python macos selenium
2个回答
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');

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()
© www.soinside.com 2019 - 2024. All rights reserved.