首页 > 解决方案 > 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.

标签: pythonseleniumautomationmicrosoft-edgeselenium-edgedriver

解决方案


我猜您使用的是 Edge Chromium,您可以参考以下步骤使用 Selenium python 代码自动化 Edge 浏览器:

  1. 从此链接下载并安装 Python 。

  2. 以管理员身份启动命令提示符。

  3. 运行以下命令以安装 Edge Selenium 工具。

    pip install msedge-selenium-tools selenium==3.141
    
  4. 从此链接安装正确版本的 Edge Web 驱动程序。(WebDriver版本应与Edge浏览器版本一致)

  5. 使用下面的代码创建一个 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)

推荐阅读