Python selenium.common.exceptions.WebDriverException:消息:将Seleniu与ChromeDriver一起使用find_element_by_id selenium时出现chrome不可访问错误
以下是html代码:Python selenium.common.exceptions.WebDriverException:消息:将Seleniu与ChromeDriver一起使用find_element_by_id selenium时出现chrome不可访问错误,python,selenium,selenium-webdriver,chrome-web-driver,Python,Selenium,Selenium Webdriver,Chrome Web Driver,以下是html代码: < input class="form-control input-lg input auto-complete" id="ymMsgInput" type="text" placeholder="Type your message ..." autocomplete="off" > Python-Selenium Chrome Web驱动程序错误: Traceback (most recent call last): File "<pyshell#
< input class="form-control input-lg input auto-complete" id="ymMsgInput" type="text" placeholder="Type your message ..." autocomplete="off" >
Python-Selenium Chrome Web驱动程序错误:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
i = s.find_element_by_id("ymMsgInput");
File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 351, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
'value': value})['value']
File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=65.0.3325.146)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
i=s.find_element_by_id(“ymMsgInput”);
文件“C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第351行,按id查找元素
返回self.find_元素(by=by.ID,value=ID_u)
文件“C:\Users\vishn\AppData\Local\Programs\Python\36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第955行,在find\u元素中
'value':value})['value']
文件“C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,执行中第312行
self.error\u handler.check\u响应(响应)
文件“C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:无法访问chrome
(会话信息:chrome=65.0.3325.146)
(驱动程序信息:chromedriver=2.36.540470(e522d04694c7ebea4ba8821272dbef4f9b818c91),平台=Windows NT 10.0.16299 x8664)
您的例外情况与查找元素无关。硒不能接触铬。你可以做两件事
chrome_options.add_argument('--no-sandbox')
chrome = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chrome_options)
错误说明了一切:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
如果用户使用的二进制文件之间存在版本兼容性,则会出现此错误,但这肯定不是您的情况:
- 使用chromedriver=2.36
- 使用chrome=65.0
- 硒版本未知
发行说明中明确提到:
支持Chrome v65-66
- 因此,两种可能的解决方案是:
- 使用ChromeOptions类最大化浏览器
- 删除选项
禁用信息栏
- 例如:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("start-maximized") driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\path\to\chromedriver.exe') driver.get('https://www.google.co.in') print("Page Title is : %s" %driver.title)
如果您的问题仍然存在,请考虑以下事项:
- 将Selenium Python客户端升级到当前级别
- 将ChromeDriver升级到稳定级别
- 将Chrome版本保持在ChromeV64.x级别。()
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 在执行测试套件之前和之后,使用该工具清除所有操作系统杂务
- 如果您的基础Chrome版本太旧,请通过卸载并安装最新的GA和Chrome发布版本
- 执行
测试
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)