Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';t';chromedriver';即使通过Selenium和Python使用ChromeDriverManager,也可以在路径中执行_Python_Selenium_Selenium Webdriver_Selenium Chromedriver_Webdriver Manager_Google Chrome - Fatal编程技术网

为什么不是';t';chromedriver';即使通过Selenium和Python使用ChromeDriverManager,也可以在路径中执行

为什么不是';t';chromedriver';即使通过Selenium和Python使用ChromeDriverManager,也可以在路径中执行,python,selenium,selenium-webdriver,selenium-chromedriver,webdriver-manager,google-chrome,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,Webdriver Manager,Google Chrome,我正试图用这段代码点击“发射地球”按钮 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install()) from selenium.webdriver.common.by import By from selenium.webdriver.support.ui imp

我正试图用这段代码点击“发射地球”按钮

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Web
from selenium.webdriver.support import expected_conditions as EC
url = 'https://www.google.com/earth/'
driver = webdriver.chrome()
driver.get(url)
wait = WebDriverWait(driver, 10)
launchEarthButton = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/header/div/nav[1]/ul[2]/li[2]/a/span/span' ))
launchEarthButton.click()
但是,我得到下面的错误消息。怎么了?作为参考,我使用的是MacOs电脑。我以前遇到过错误路径的问题,但我通过ChromeDriverManager解决了它

FileNotFoundError                         Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py in start(self)
     71             cmd.extend(self.command_line_args())
---> 72             self.process = subprocess.Popen(cmd, env=self.env,
     73                                             close_fds=platform.system() != 'Windows',

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    853 
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1701                         err_msg = os.strerror(errno_num)
-> 1702                     raise child_exception_type(errno_num, err_msg, err_filename)
   1703                 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
<ipython-input-9-940dd1aefbaf> in <module>
      7 from selenium.webdriver.support import expected_conditions as EC
      8 url = 'https://www.google.com/earth/'
----> 9 driver = webdriver.Chrome()
     10 driver.get(url)
     11 wait = WebDriverWait(driver, 10)

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     71             service_args=service_args,
     72             log_path=service_log_path)
---> 73         self.service.start()
     74 
     75         try:

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py in start(self)
     79         except OSError as err:
     80             if err.errno == errno.ENOENT:
---> 81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
     83                         os.path.basename(self.path), self.start_error_message)

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
FileNotFoundError回溯(最近一次调用)
/开始时的Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py(self)
71 cmd.extend(self.command\u line\u args())
--->72 self.process=subprocess.Popen(cmd,env=self.env,
73 close_fds=platform.system()!=“Windows”,
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py in_uuuuinit_uuu(self、args、bufsize、executable、stdin、stdout、stderr、preexec_fn、close_fds、shell、cwd、env、universal_换行、startupinfo、creationflags、restore_信号、start_new_会话、pass_fds、编码、错误、文本)
853
-->854 self.\u execute\u child(args、execute、preexec\u fn、close\u fds、,
环境保护署西湾道855号,
/库/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py in_execute_child(self、args、execute、preexec_fn、close_fds、pass_fds、cwd、env、startupinfo、creationflags、shell、p2cread、p2c2cwrite、c2pwrite、errread、errwrite、restore_信号、start_new_会话)
1701 err_msg=os.strerror(errno_num)
->1702引发子项异常类型(错误号、错误消息、错误文件名)
1703引发子项异常类型(错误消息)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“chromedriver”
在处理上述异常期间,发生了另一个异常:
WebDriverException回溯(最近一次调用上次)
在里面
7从selenium.webdriver.support将预期的_条件导入为EC
8网址:https://www.google.com/earth/'
---->9 driver=webdriver.Chrome()
10驱动程序获取(url)
11等待=WebDriverWait(驱动程序,10)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py in\uuuuuu init\uuuuuuuuuuuuuuu(self、可执行路径、端口、选项、服务参数、所需的功能、服务日志路径、chrome\u选项、保持活动状态)
71服务参数=服务参数,
72日志路径=服务日志路径)
--->73自助服务启动()
74
75尝试:
/开始时的Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py(self)
79除操作错误作为错误外:
80如果err.errno==errno.enoint:
--->81提出WebDriverException(
82“'%s'可执行文件需要位于路径中。%s”%(
83 os.path.basename(self.path)、self.start\u错误消息)
WebDriverException:消息:“chromedriver”可执行文件需要位于路径中。请参阅https://sites.google.com/a/chromium.org/chromedriver/home

您很接近。正如您使用的:

driver = webdriver.Chrome(ChromeDriverManager().install())
缓存/下载的内容将用于启动新的浏览上下文


因此,您需要删除
driver=webdriver.Chrome()

的第二个实例,这是否回答了您的问题?当您使用Mac Os时,“chromedriver.exe”应该被称为“chromedriver”,如果需要的话,其他简单的方法是将chromedriver.exe放在python目录的Scripts文件夹中