Score:0

How do I install Microsoft Edge driver for selenium testing in Python 3?

cn flag

We are trying to setup an automation testing environment for a web application. This web application will be hosted on Ubuntu server. In QA environment, we are trying to perform automated testing.

Environment information is as below:

  • Operating System: Ubuntu 20.04 and/or 21.04
  • Programming Language used: Python3 (3.8.10)
  • Automation Tool: Selenium
  • Desired browser: MS Edge

Flexibility:

We can use different version of Python or Ubuntu for this to work, but since MS Edge is client's preferred browser that can't be replaced with Firefox or other available browser. Though we can use different version of edge, if it works. And we are able to test the same in chrome browser successfully. We can use different Linux Distros as long as it is stable version.

What we have already tried?

Also tried to follow the same instruction as we did for chrome. For installing chrome driver we followed 'https://www.thenerdlife.com/blog/how-to-install-chromedriver-on-ubuntu/'. So we did the same for edge and replaced "chromedriver" with "msedgedriver" in the script.

We have installed MS Edge (DEV v93.0.933.1) on Ubuntu 20.04. As for webdriver, we found it on 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/' and copied the file to the same location as python test file.

We also tried to rename the "msedgedriver" to "MicrosoftWebDriver.exe" (the file that was placed with python program). Coming from windows background, this thing usually works.

Python program

from selenium import webdriver
driver = webdriver.Edge()
driver.get('https://www.google.com/')
> Traceback (most recent call last):
  File "/home/devang/.local/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'MicrosoftWebDriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/devang/GitHub/AutomationSampleTest/ieEdgeBrowse.py", line 3, in <module>
    driver = webdriver.Edge()
  File "/home/devang/.local/lib/python3.8/site-packages/selenium/webdriver/edge/webdriver.py", line 56, in __init__
    self.edge_service.start()
  File "/home/devang/.local/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687

EDIT Also tried following code to pass the driver file location:

from selenium import webdriver
from selenium.webdriver.edge.options import Options
options = webdriver.EdgeOptions()
options.use_chromium = True
options.binary_location = "/home/devang/GitHub/AutomationSampleTest/msedgedriver"
driver = webdriver.Edge(options = options)
driver.get('https://www.google.com/') 

For above code it is throwing different error:

Traceback (most recent call last):
  File "/home/devang/GitHub/AutomationSampleTest/ieEdgeBrowse.py", line 3, in <module>
    options = webdriver.EdgeOptions()
AttributeError: module 'selenium.webdriver' has no attribute 'EdgeOptions'

Question:

Is it even possible to do automated testing for MS Edge in Ubuntu using Python3 and Selenium?

If yes then how? Please break it down to small easy steps to follow as I am a new Ubuntu user.

muru avatar
us flag
Did you try setting the path to the `msedgedriver` file using `options.binary_location` (like in https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python#choose-specific-browser-binaries-chromium-only)? Is the file executable?
Devang avatar
cn flag
@muru This step is for windows OS. How do I do the same for ubuntu? I have also mentioned the link from where i downloaded it. But it os not .exe, since this is for linux.
muru avatar
us flag
Something like `options.binary_location = "/path/to/msedgedriver"`, presumably.
Devang avatar
cn flag
I have update the code and error it is throwing in question. "msedgedriver" is the file. This file didn't had any extension. I suppose that's how Ubuntu works... Once more thing, I also executed this command mention in the link @muru provided "pip install msedge-selenium-tools selenium==3.141"
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.