MSEdgeDriver(Chromium)在版本79.0.309.0之后不起作用

时间:2019-10-28 12:02:31

标签: python selenium-webdriver selenium-chromedriver microsoft-edge

我在脚本中使用了Microsoft Edge Webdriver(Chromium)和Python3。

webdriver配置如下:

driveroptions = Options()
driveroptions.add_argument('--inprivate')
driveroptions.add_argument('--disable-infobars')
driveroptions.add_argument('--start-maximized')
driveroptions.add_argument('--auto-open-devtools-for-tabs')
driveroptions.add_argument('--user-data-dir=D:\\Selenium_Edge_Chromium_UserData')
driveroptions.binary_location = "C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\Edge SxS\\Application\\msedge.exe"
# driver = webdriver.Chrome(options=driveroptions, executable_path="msedgedriver.309.exe", service_log_path="D:\\X.txt")
driver = webdriver.Chrome(options=driveroptions, executable_path="msedgedriver.exe", service_log_path="D:\\X.txt")

driver.set_page_load_timeout(40)
wait = WebDriverWait(driver, 40)
driver.get(base_url)

自从我第一次使用Canary以来,它运行良好,但是在79.0.309.0版(不包括在内)之后,驱动程序只是返回错误:

Message: session not created: No matching capabilities found

服务记录在这里:

[1572262712.029][INFO]: Starting MSEdgeDriver 80.0.315.0 (9e44865e0573123f4459e64bc4e043fee13eb7ec)
[1572262712.029][INFO]: Please protect ports used by MSEdgeDriver and related test frameworks to prevent access by malicious code.
[1572262712.567][INFO]: [0b47b609c87652c1d1f004bfac456076] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [ "--inprivate", "--disable-infobars", "--start-maximized", "--auto-open-devtools-for-tabs", "--user-data-dir=D:\\Selenium_Edge_Chromium_UserData" ],
            "binary": "C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\Edge SxS\\Application\\msedge.exe",
            "extensions": [  ]
         },
         "platformName": "any"
      },
      "firstMatch": [ {

      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "goog:chromeOptions": {
         "args": [ "--inprivate", "--disable-infobars", "--start-maximized", "--auto-open-devtools-for-tabs", "--user-data-dir=D:\\Selenium_Edge_Chromium_UserData" ],
         "binary": "C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\Edge SxS\\Application\\msedge.exe",
         "extensions": [  ]
      },
      "platform": "ANY",
      "version": ""
   }
}
[1572262712.571][INFO]: [0b47b609c87652c1d1f004bfac456076] RESPONSE InitSession ERROR session not created: No matching capabilities found

如果msedgedriver版本保持在79.0.309.0,我仍然可以使用我的脚本。

但是新版本的msedgedriver(79.0.313.0、80.0.315.0等)发生了什么?

他们放弃一些受支持的功能吗?

已更新

Microsoft Edge (Chromium): 80.0.315.0
msedgedriver for Microsoft Edge (Chromium): 80.0.315.0
->
Message: session not created: No matching capabilities found
Microsoft Edge (Chromium): 79.0.313.0
msedgedriver for Microsoft Edge (Chromium): 79.0.313.0
->
Message: session not created: No matching capabilities found
Microsoft Edge (Chromium): 79.0.309.0
msedgedriver for Microsoft Edge (Chromium): 79.0.309.0
->
(Works well without issue)

以及79.0.309.0(及更低版本)的msedgedriver:

Microsoft Edge (Chromium): (version before 79.0.309.0)
msedgedriver for Microsoft Edge (Chromium): (version before 79.0.309.0, = browser version)
->
(Works without issue)
Microsoft Edge (Chromium): 79.0.309.0
msedgedriver for Microsoft Edge (Chromium): 79.0.309.0
->
(Works without issue)
Microsoft Edge (Chromium): 79.0.313.0
msedgedriver for Microsoft Edge (Chromium): 79.0.309.0
->
(Works without issue)
Microsoft Edge (Chromium): 80.0.315.0
msedgedriver for Microsoft Edge (Chromium): 79.0.309.0
->
(Works without issue)

PS: 我的GetEdgeDriver.BAT,它将当前安装的Microsoft Edge(Chromium)Canary浏览器的版本与从https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/下载的当前webdriver进行比较。如果后者低于前者,则会下载msedgedriver.exe并覆盖旧的。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM GNUWIN32 required

REM SET ONEDRIVE=%UserProfile%\OneDrive
REM This file is located in OneDrive\Files\BIN
SET ONEDRIVE=%~DP0..\..

SET EDGE_DIR=%UserProfile%\AppData\Local\Microsoft\Edge SxS\Application

IF NOT EXIST "%EDGE_DIR%\msedge.exe" ECHO MSEdge not found at %EDGE_DIR%! & GOTO :EOF
FOR /F %%I IN ('DIR /B "%EDGE_DIR%" ^| grep -E [0-9]+\.[0-9]+\.') DO SET MSEDGE_VERSION=%%I& GOTO :MSEDGE_VERSION_RETRIEVED
:MSEDGE_VERSION_RETRIEVED
ECHO MSEdge browser version: %MSEDGE_VERSION%

FOR /F %%I IN ('MSEDGEDRIVER -V ^| awk "{print $2}"') DO SET HAVE_DRIVER_VERSION=%%I& GOTO :HAVE_DRIVER_VERSION_RETRIEVED
:HAVE_DRIVER_VERSION_RETRIEVED
ECHO MSEdge driver version in OneDrive: %HAVE_DRIVER_VERSION%

REM e.g. https://msedgedriver.azureedge.net/79.0.287.0/edgedriver_win64.zip
IF %MSEDGE_VERSION% GTR %HAVE_DRIVER_VERSION% (
    SET URL=https://msedgedriver.azureedge.net/%MSEDGE_VERSION%/edgedriver_win64.zip
    ECHO.
    ECHO Downloading !URL! -^> %TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip
    REM -C -
    REM continue previous download and skip if existing download
    REM -k --insecure
    curl -C - -s -L -k -o "%TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip" -g "!URL!"
    REM curl -C - -s -L --insecure -o "%TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip" -g "!URL!"
    REM unzip -uoqq "%TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip"
    ECHO Extracting %TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip -^> %~DP0msedgedriver.exe
    REM extract msedgedriver.exe inside edgedriver_win64_%MSEDGE_VERSION%.zip to %ONEDRIVE%\Files\BIN folder with the same name
    REM 7z x -y -o"C:\Users\Administrator\OneDrive\Files\BIN" "%TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip" msedgedriver.exe > nul
    7z x -y -o"%ONEDRIVE%\Files\BIN" "%TEMP%\edgedriver_win64_%MSEDGE_VERSION%.zip" msedgedriver.exe > nul

    REM MSEDGEDRIVER -V
    FOR /F %%I IN ('MSEDGEDRIVER -V ^| awk "{print $2}"') DO SET HAVE_DRIVER_VERSION=%%I& GOTO :NEW_DRIVER_VERSION_RETRIEVED
    :NEW_DRIVER_VERSION_RETRIEVED
    ECHO New MSEdge driver version in OneDrive: %HAVE_DRIVER_VERSION%
)

3 个答案:

答案 0 :(得分:0)

我尝试了以下功能,它起作用了,您可以尝试一下:

{
    "desiredCapabilities": {
            "nativeEvents": false,
            "browserName": "chrome",
            "version": "",
            "platform": "ANY",
            "javascriptEnabled": true,
            ...
    }
}

答案 1 :(得分:0)

浏览器和Webdriver必须与版本号的前3个元组匹配。

在chrome中,有一个版本检查,可告诉您浏览器和webdriver是否不匹配。 msedge提供了更多的分散性:No matching capabilities found

我使用的是巧克力Microsoft Edge Insider - Beta,它安装了msedge浏览器,当前版本为79.0.309.65。

这意味着我不能使用当前为79.0.313.0的最新的79.x msedgedriver,我必须使用79.0.309.x。

我已经在selenium驱动程序中实现了一个简单的测试,可以在开始之前进行检查。

答案 2 :(得分:0)

最终解决了我的问题。

  1. 将Selenium 3.14安装/升级到Selenium 4.0.0a5
  2. 将Python代码更改为以下内容:
# using edge directly, since you can see 'selenium.webdriver.chromium.webdriver' used in site-packages\selenium\webdriver\edge\webdriver.py
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.webdriver import WebDriver
...
...
driveroptions = Options()
# remember to set use_chromium
driveroptions.use_chromium = True
driveroptions.add_argument('--start-maximized')
driveroptions.binary_location = env_programfiles_x86 + "\\Microsoft\\Edge\\Application\\msedge.exe"

service = Service(executable_path="msedgedriver.exe")
driver = webdriver.Edge(options=driveroptions, service=service)

driver.set_page_load_timeout(40)
driver.get(page_url)