python - MSEdgeDriver - session not created: No matching capabilities found error on Selenium with Python
问题描述
Having some trouble getting our automation to run on Microsoft Edge. Have the correct browser version driver installed and have tried a few other 'fixes' to no avail. This is using Selenium with Python3 on PyCharm.
Going back to the beginning, this is my code...
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.edge.options import Options
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
options = Options()
driver = webdriver.Edge(executable_path='/Users/james.stott/PycharmProjects/venv/Selenium/Remote/msedgedriver')
And the following is the error raised...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found
Any help at all, would be greatly appreciated.
解决方案
我猜您使用的是 Edge Chromium,您可以参考以下步骤使用 Selenium python 代码自动化 Edge 浏览器:
从此链接下载并安装 Python 。
以管理员身份启动命令提示符。
运行以下命令以安装 Edge Selenium 工具。
pip install msedge-selenium-tools selenium==3.141
从此链接安装正确版本的 Edge Web 驱动程序。(WebDriver版本应与Edge浏览器版本一致)
使用下面的代码创建一个 Python 文件,并根据您自己的要求对其进行修改。
from msedge.selenium_tools import Edge, EdgeOptions options = EdgeOptions() options.use_chromium = True options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" driver = Edge(executable_path = r"D:\selenium web drivers\edge driver\msedgedriver.exe", options = options) # Modify the path here... driver.get("https://example.com")
更新:
如果您使用的是 Mac OS,则需要发送功能。您可以尝试发送一个空功能:
desired_cap={}
driver = webdriver.Edge(executable_path='/Users/james.stott/PycharmProjects/venv/Selenium/Remote/msedgedriver', capabilities=desired_cap)
推荐阅读
- javascript - 如何根据其在页面上的位置将任何具有类的元素附加到另一个类的第一个实例?
- c - 如何将整数分成多个数字?
- java - 如何在此代码中跟踪多个异步任务
- macos - kVTCompressionPropertyKey_DataRateLimits 属性不受硬件编码器的尊重,macOS
- mysql - 在 S3 中临时保存大查询结果(~100k 行)的最佳方法是什么?
- php - Silverstripe 3: Tinymce,配置外部链接
- bit-manipulation - 当已知集合时,按位 OR 和 AND NOT 与加法和减法相同吗?
- python - 处理 arg 验证的最佳方法
- ios - 协议后的 JSON 解析
- php - 致命错误:在第 4 行 C:\appserv\www\Cocolani\php\req\register.php 中的 null 上调用成员函数 get()