selenium 'webdriver' not being recognised (python)

1.1k views Asked by At

I have installed selenium through python using pip (I ran):

pip install selenium

I'm using Python 3.9.0 and the driver argument isn't being recognized.

My current code.

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

In this code. there is no issue with the import command but driver is not being recognised as valid syntax.

Any help?

2

There are 2 answers

0
Yu Zhou On BEST ANSWER

You need to run the command below to install the MS Edge Selenium tools:

pip install msedge-selenium-tools selenium==3.141

Then use the code below, it can work well on my side:

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')

Please note to use the same version of Edge Webdriver as the Edge browser and change the paths in the code to your owns.

0
undetected Selenium On

As per the documentation in Enhancing automated testing in Microsoft Edge with new WebDriver capabilities, W3C protocol support, and automatic updates, now MicrosoftWebDriver is a Windows Feature on Demand (FoD), which ensures that it’s always up to date automatically, and enables some new ways to get Microsoft WebDriver.


Steps

  • Enable Developer Mode which will install the appropriate version of WebDriver.

    Open Settings app > Go to Update & Security > For Developer and then select "Developer Mode".
    
  • You can also install a standalone version of WebDriver in one of two ways:

  • Search "Manage optional features" from Start, then select "Add a Feature", "WebDriver".

  • Install via DISM by running the following command in an elevated command prompt:

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

Note: When installing MicrosoftWebDriver through the DISM command, by default the webdriver is installed within the following sub-directories:

  • 64 bit:

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

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

Usage

You can use the following code block:

from selenium import webdriver

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

References

You can find a couple of relevant detailed discussions in:


tl; dr

As per Microsoft Edge Developer Guide:

EdgeHTML 18 includes the following new and updated features shipped in the current release of the Microsoft Edge platform, as of the Windows 10 October 2018 Update (10/2018, Build 17763). For changes in specific Windows Insider Preview builds, see the Microsoft Edge Changelog and What's New in EdgeHTML.