0

我已经使用 pip 通过 python 安装了 selenium(我跑了):

pip install selenium

我正在使用 Python 3.9.0,并且无法识别驱动程序参数。

我当前的代码。

import selenium
from selenium import webdriver
filepath = r"D:\msedgedriver.exe"
webdriver.Edge(filepath)
options=driver.EdgeOptions()

在这段代码中。导入命令没有问题,但driver未被识别为有效语法。

有什么帮助吗?

4

2 回答 2

0

根据使用新的 WebDriver 功能、W3C 协议支持和自动更新增强 Microsoft Edge 中的自动化测试中的文档,现在 MicrosoftWebDriver 是一种Windows Feature on Demand (FoD),可确保它始终自动更新,并启用一些新的获取 Microsoft WebDriver 的方法。


脚步

  • 启用将安装适当版本的 WebDriver 的开发人员模式。

    Open Settings app > Go to Update & Security > For Developer and then select "Developer Mode".
    
  • 您还可以通过以下两种方式之一安装独立版本的 WebDriver:

  • 从开始搜索“管理可选功能”,然后选择“添加功能”、“WebDriver”。

  • 通过在提升的命令提示符下运行以下命令来通过 DISM 安装:

    DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
    

注意:通过命令安装MicrosoftWebDriverDISM时,默认情况下 webdriver 安装在以下子目录中:

  • 64位:

    C:\\Windows\\SysWOW64\\MicrosoftWebDriver.exe
    
  • 32位:

    C:\\Windows\\System32\\MicrosoftWebDriver.exe
    

用法

您可以使用以下代码块:

from selenium import webdriver

driver = webdriver.Edge(executable_path=r'C:\WebDrivers\MicrosoftWebDriver.exe')
driver.get("https://www.google.com/")

参考

您可以在以下位置找到一些相关的详细讨论:


tl; 博士

根据Microsoft Edge 开发人员指南

EdgeHTML 18 包括 Microsoft Edge 平台的当前版本中提供的以下新功能和更新功能,截至2018 年 10 月 10 日的 Windows 更新(10/2018,内部版本 17763)。有关特定Windows Insider Preview 版本的更改,请参阅Microsoft Edge 更改日志EdgeHTML 中的新增功能

于 2020-11-29T17:03:00.103 回答
0

您需要运行以下命令来安装 MS Edge Selenium 工具:

pip install msedge-selenium-tools selenium==3.141

然后使用下面的代码,它可以在我这边运行良好:

from msedge.selenium_tools import Edge, EdgeOptions

edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
driver = Edge(options = edge_options, executable_path = r"D:\msedgedriver.exe")
driver.get('https://microsoft.com')

请注意使用与 Edge 浏览器相同版本的 Edge Webdriver,并将代码中的路径更改为您自己的。

于 2020-11-30T06:35:01.077 回答