【问题标题】:selenium 'webdriver' not being recognised (python)硒'webdriver'未被识别(python)
【发布时间】:2020-11-29 16:45:43
【问题描述】:

我已经通过 python 使用 pip 安装了 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 未被识别为有效语法。

有什么帮助吗?

【问题讨论】:

  • 这里同样适用driver.get('url')
  • 你在用pycham吗?
  • 我没有使用 pycharm
  • 嗨@chunguslover3000 这个问题怎么样?我下面的回答对解决这个问题有帮助吗?如果是这样,您可以参考this,它可以帮助其他社区成员将来解决类似问题。感谢您的理解。

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


【解决方案1】:

您需要运行以下命令来安装 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,并将代码中的路径更改为您自己的。

【讨论】:

    【解决方案2】:

    根据Enhancing automated testing in Microsoft Edge with new WebDriver capabilities, W3C protocol support, and automatic updates 中的文档,现在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
      

    注意:当通过DISM 命令安装MicrosoftWebDriver时,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 Developer Guide

    EdgeHTML 18 包括从Windows 10 October 2018 Update(10/2018,内部版本 17763)开始在当前版本的 Microsoft Edge 平台中提供的以下新功能和更新功能。有关特定 Windows Insider 预览版本的更改,请参阅 Microsoft Edge ChangelogWhat's New in EdgeHTML

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 2012-02-28
      • 1970-01-01
      相关资源
      最近更新 更多