当我运行脚本时,出现此错误
Traceback (most recent call last):
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/ishaq/AppData/Local/Programs/Python/Python36/headless.py", line 9, in <module>
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
这是我的剧本
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location =
r'C:\Users\ishaq\Desktop\chrome\chromedriver.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),
chrome_options=chrome_options)
driver.get("http://www.duo.com")
magnifying_glass = driver.find_element_by_id("js-open-icon")
if magnifying_glass.is_displayed():
magnifying_glass.click()
else:
menu_button = driver.find_element_by_css_selector(".menu-trigger.local")
menu_button.click()
search_field = driver.find_element_by_id("site-search")
search_field.clear()
search_field.send_keys("Olabode")
search_field.send_keys(Keys.RETURN)
assert "Looking Back at Android Security in 2016" in driver.page_source
driver.close()
如果我们分析日志,似乎主要问题在于in start os.path.basename(self.path)
和随后的错误消息
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
。
因此,从错误中很明显,Python客户端无法找到 chromedriver
二进制文件。
您必须在这里注意以下几点:
chrome_options.binary_location
:参数配置 chrome.exe
不是 chromedriver.exe
os.path.abspath("chromedriver")
将选择的文件路径, chromedriver
但不会 chromedriver.exe
在末尾追加。Windows 8
系统开始 Chrome
在 Headless Mode
: from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("http://www.duo.com")
print("Chrome Browser Initialized in Headless Mode")
driver.quit()
print("Driver Exited")
...我不断收到以下错误消息: 但是-如上所述-可执行文件是(!)在路上...这是怎么回事?
环境-Mac/Python/Selenium IDE-py charm 硒.common.exceptions.Web驱动程序异常: 消息: “铬驱动程序” 可执行文件需要位于 PATH 中。请参阅 https://sites.google.com/a/chromium.org/chromedriver/home 请帮我解决这个问题。
我写了这个: 我得到了以下错误: 回溯(最近一次调用):文件“C:\Users\atrei\AppData\Local\Programs\Python38-32\lib\site packages\selenium\webdriver\common\service.py”,第72行,在start self中。进程=子进程。Popen(cmd,env=self.env,文件“C:\Users\atr
我使用基于flask的应用程序设置了python robot框架 来自阿尔卑斯山:最新拷贝。 /appWORKDIR /appRUN ls-la/RUN apk add--no-acacacecsqlite py3-pip RUN pip3安装-rrequirements.txtENVFLASK_PORT8181 ENVFLASK_APPdemo_appCMD["sh","run.sh"]COPY
问题内容: 我的本地Chrome 67 Python 3.5.0 Selenium 3.12.0具有以下环境 我已经下载了2.39版的chromedriver 我有.py文件,如下所示 我收到以下错误。 我也尝试过使用其他网络驱动程序,如geckodriver.exe仍然相同的错误。 请帮助我解决此错误。 谢谢! 问题答案: 乍一看,您的代码试用似乎在 参数 execute_path* 的 值 中
简短: 在https://automatetheboringstuff.com/chapter11阅读了使用selenium模块控制浏览器后,我试图在PyDev的虚拟环境中运行SeleniumChrome驱动程序。我已经设法从PyDev外部做到了这一点,但从内部,我得到了: < code > selenium . common . exceptions . web driver exception