简体   繁体   English

如何确定哪个 MS Edge 驱动程序与我的操作系统版本兼容,以启用 web 自动化和 Python 的 Selenium?

[英]How do I determine which MS Edge Driver is compatible with my OS Version to enable web automation with Selenium for Python?

I've been using Selenium with the Edge Driver for some time.一段时间以来,我一直在使用 Selenium 和边缘驱动程序。 I've been instantiating my Edge Driver by specifying the executable_path= parameter with no issues.我一直在通过指定executable_path=参数来实例化我的 Edge Driver,没有任何问题。 However, I recently switched my web automation project to use the webdriver_manager , ie, webdriver_manager.microsoft import EdgeChromiumDriverManager .但是,我最近将我的 web 自动化项目切换为使用webdriver_manager ,即webdriver_manager.microsoft import EdgeChromiumDriverManager Now, when I command the driver to navigate to any webpage - it opens for one second, then immediately closes.现在,当我命令驱动程序导航到任何网页时 - 它会打开一秒钟,然后立即关闭。 The current troubleshooting step I'm on is ensuring that the Edge Driver I'm using (the one downloaded by using the webdriver_manager module) is compatible with my current OS Version, but now I'm stumped.我正在进行的当前故障排除步骤是确保我正在使用的 Edge 驱动程序(通过使用webdriver_manager模块下载的驱动程序)与我当前的操作系统版本兼容,但现在我很难过。 I don't know how to find which MS Edge Driver is compatible/correct for my current OS build - I see no patterns when comparing the two, eg:我不知道如何找到与我当前的操作系统版本兼容/正确的 MS Edge 驱动程序 - 在比较两者时我看不到任何模式,例如:

My current OS:我目前的操作系统:

在此处输入图像描述

The webdriver downloaded by the webdriver_manager : webdriver_manager 下载的webdriver_manager

在此处输入图像描述

And here is a link to all MS Edge Drivers:这是所有 MS Edge 驱动程序的链接:

https://msedgewebdriverstorage.z22.web.core.windows.net/ https://msedgewebdriverstorage.z22.web.core.windows.net/

So, how do I find the Edge Driver that is "right" for my OS?那么,如何找到适合我的操作系统的 Edge 驱动程序? When I look at these two numbers: OS build - 22000.795 and Edge webdriver version - 103.0.1264.77;当我查看这两个数字时:操作系统版本 - 22000.795 和 Edge webdriver 版本 - 103.0.1264.77; I see no pattern or way of determining which driver is compatible.我看不到确定哪个驱动程序兼容的模式或方法。 Maybe, I'm using the webdriver_manager module improperly?也许,我不正确地使用了webdriver_manager模块? I know I can use the executable path, but I'm under the impression that using the webriver_manager automates the install of new releases for you so you don't have to update your script to new edge drivers in the future.我知道我可以使用可执行路径,但我的印象是使用webriver_manager自动为您安装新版本,因此您将来不必将脚本更新为新的边缘驱动程序。

For additional context, here is my code (using Facebook's domain just as an example):对于其他上下文,这是我的代码(仅以 Facebook 的域为例):

from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(service = EdgeService(EdgeChromiumDriverManager().install()))

driver.get('https://facebook.com')

The SeleniumBase driver manager works well with Edge: SeleniumBase驱动程序管理器与 Edge 配合得很好:

from seleniumbase import get_driver

driver = get_driver("edge", headless=False)
driver.get("https://facebook.com")
import time; time.sleep(1)
driver.quit()

(Here's another example using the raw driver manager: raw_browser_launcher.py ) (这是另一个使用原始驱动程序管理器的示例: raw_browser_launcher.py

Alternatively, you can use the more simple format with automatic setUp and tearDown, but then you need to run your test with pytest and add --edge as a command-line option to use Edge:或者,您可以使用更简单的格式和自动设置和拆卸,但是您需要使用pytest运行测试并添加--edge作为使用 Edge 的命令行选项:

from seleniumbase import BaseCase

class MyTestClass(BaseCase):
    def test_facebook(self):
        self.open("https://facebook.com")
        self.sleep(1)
pytest test_facebook.py --edge
========================= test session starts ==========================
platform darwin -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/michael/github/SeleniumBase/examples, configfile: pytest.ini
plugins: html-2.0.1, xdist-2.5.0, forked-1.4.0, rerunfailures-10.2, ordering-0.6, cov-3.0.0, metadata-2.0.2, seleniumbase-3.5.11
collected 1 item                                                       

test_facebook.py .

========================== 1 passed in 4.40s ===========================

It's working now (ie, with the same code example in my original question, the MS Edge window now opens as commanded and remains open).它现在正在工作(即,在我原来的问题中使用相同的代码示例,MS Edge window 现在按命令打开并保持打开状态)。 I found the MS Docs regarding Edge webdriver installation/configuration我找到了有关 Edge webdriver 安装/配置的 MS Docs

https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp

and here are the steps I followed:这是我遵循的步骤:

  1. The first step is to ensure that your Edge webdriver ("msedgedriver.exe") version matches your Edge browser version (I read a tech blog that said my OS build version needed to match my "msedgedriver.exe" version - thinking maybe that's wrong now?)第一步是确保您的 Edge webdriver ("msedgedriver.exe") 版本与您的 Edge浏览器版本匹配(我读过一篇技术博客说我的操作系统构建版本需要与我的 "msedgedriver.exe" 版本匹配 - 认为这可能是错误的现在?)

  2. I navigated to About Microsoft Edge in settings: edge://settings/help我在设置中导航到关于 Microsoft Edge :edge://settings/help

which displays my current MS Edge version - It was covered with a prompt to update Edge - so I did.它显示了我当前的 MS Edge 版本 - 它被提示更新 Edge - 所以我做到了。 Checked after update and my version was: 104.0.1293.47更新后检查,我的版本是: 104.0.1293.47

  1. On a whim, suspecting that maybe my Edge browser update was the cause for webdriver_manager downloading the incompatible msedgedriver.exe , I attempted to run my script again (exact same one I posted in original question)一时兴起,我怀疑我的 Edge 浏览器更新可能是导致webdriver_manager下载不兼容的msedgedriver.exe的原因,我尝试再次运行我的脚本(与我在原始问题中发布的完全相同)

And it worked - I checked the msedgedriver.exe version right after and noticed that webdriver_manager downloaded a new version: 104.0.1293 - which matches my current Edge Browser version.它起作用了——我马上检查了msedgedriver.exe版本,发现webdriver_manager下载了一个新版本:104.0.1293——它与我当前的 Edge 浏览器版本相匹配。

So, I'm not 100% sure what the cause for the webdriver_manager failing to download the correct version (to match my browser) was - but until I updated my MS Edge Browser, no new drivers were installed.所以,我不能 100% 确定webdriver_manager未能下载正确版本(以匹配我的浏览器)的原因是什么 - 但在我更新我的 MS Edge 浏览器之前,没有安装新的驱动程序。 Then after update and running the script, the right driver is installed and it's working fine now.然后在更新并运行脚本后,安装了正确的驱动程序,它现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium 远程 Web 驱动程序:如何确定使用的是哪个 IEDriverServer.exe(32 位或 64 位)? - Selenium Remote Web Driver: How do I determine which IEDriverServer.exe (32-bit or 64-bit) is being used? python selenium 3 Edge web 驱动程序错误 - Error in python selenium 3 Edge web driver 带有 MS Edge 浏览器的 Python (Selenium):'Connection aborted.', ConnectionResetError(10054, ...)“Microsoft Web Driver 已停止工作” - Python (Selenium) with MS Edge browser: 'Connection aborted.', ConnectionResetError(10054, ...) "Microsoft Web Driver has stopped working" Python Edge 驱动程序 Web 自动化帮助 - 找不到 Xpath - Python Edge Driver Web Automation Help - Cannot find Xpath Python Selenium Web Automation 如何单击登录按钮 - Python Selenium Web Automation How Do You Click A Login Button 我在OS X Sierra上拥有哪个GCC版本 - Which GCC version do I have on my OS X Sierra 如何检查哪个版本的 Python 正在运行我的脚本? - How do I check which version of Python is running my script? 如果我的 chromedriver 与 chrome 版本不兼容,我该如何修复它? - How do i fix my chromedriver if its not compatible with chrome version? 如何找出与我的代码兼容的所有以前的python版本 - How do I find out all previous versions of python with which my code is compatible 如何 24/7 全天候运行 selenium Web 驱动程序脚本 - How do I run a selenium web driver script 24/7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM