Using python selenium for Microsoft edge
Asked Answered
U

6

6

I am trying to use pythons selenium for Microsoft edge but I keep getting this error:

WebDriverException: Message: unknown error: cannot find Microsoft Edge binary

I downloaded the latest version of the edge driver. Here is my code:

from selenium import webdriver
from selenium.webdriver.remote import webelement
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time
from bs4 import BeautifulSoup
import os
from datetime import datetime
from selenium.webdriver import ActionChains

driver = webdriver.Edge(executable_path = 'C:\\Users\\Downloads\\edgedriver_win32\\msedgedriver.exe')
def get_trulia_estimate(address):
    driver.get('https://www.trulia.com/')
    print(address)
    element = (By.ID, 'homepageSearchBoxTextInput')

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable(element)).click()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable(element)).send_keys(address)

    search_button = (By.CSS_SELECTOR, "button[data-auto-test-id='searchButton']")

    WebDriverWait(driver, 50).until(EC.element_to_be_clickable(search_button)).click()

    time.sleep(3) 
Ulent answered 23/7, 2019 at 17:39 Comment(1)
Seems like you're missing the user in your path there... also note that the latest EdgeDriver versions are installed via Edge itself... they call it a "Feature on Demand": developer.microsoft.com/en-us/microsoft-edge/tools/webdriver The path will always be the same after it installs...SYSWOW64. (or possibly System32 on 32-bit OS?)Studious
G
2

WebDriver cannot find your MS Edge path, u can try to uninstall and reinstall Edge. If its not gonna help add Edge location to your system path or use --binary argument.

Grovergroves answered 23/7, 2019 at 18:1 Comment(16)
Add edge location to the edge driver I downloaded?Ulent
Did u try to reinstall it first?Grovergroves
if its not gonna help try to add Edge path to system path.Grovergroves
I did reinstall it but still getting the same errorUlent
u r on windows or mac?Grovergroves
Windows unfortunatelyUlent
Edge should be installed in default location, not the one u created.Grovergroves
Do u know how to add system path?Grovergroves
I think so yes, in the environment variables right?Ulent
The code finds the executable. When it is not finding it clearly says that the executable is not in the path. Anyways, I added it to the path and I am getting the same error as before. I was originally pointing to the location of the path which I believe is no different than adding that same path to environment variables pathUlent
It's says that executable not in the path, if it's can't find driver. In your case its can't find EDGE, u were pointing to driver path, not to Edge path if u r talking about this line- "driver = webdriver.Edge(executable_path = 'C:\\Users\\Downloads\\edgedriver_win32\\msedgedriver.exe')"Grovergroves
What path u were adding to system variable?Grovergroves
I was adding the path to where the exe is stored.Ulent
Something like this - "C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe"?Grovergroves
This is what u need - automationtestinghub.com/…Grovergroves
Let us continue this discussion in chat.Grovergroves
M
7

This post is quite old now, but hopefully I can help anyone that stumbles upon the same issue in future!

The problem is that you're using the wrong webdriver. Edge exists in two different versions, implemented on two non-interchangeable engines -- Chromium Edge and EdgeHTML (the default version at the time of writing). Each of these two versions has a different webdriver associated with it, with Chromium Edge's being "msedgedriver.exe", and EdgeHTML's being "MicrosoftWebDriver.exe".

You are using the EdgeHTML version of Edge, while trying to run the Chromium Edge webdriver. The 'cannot find Microsoft Edge binary' error Selenium spits out comes from this.

Luckily it is easy to install the right webdriver. If you have a Edge 17 or older, you can install the driver here. Make sure you download the EdgeHTML driver, not the Chromium driver, and add it to your PATH. For Edge 18 and later, you don't have to download anything. Simply run in the command prompt the command: DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0.

Mclin answered 8/1, 2020 at 4:4 Comment(0)
G
2

WebDriver cannot find your MS Edge path, u can try to uninstall and reinstall Edge. If its not gonna help add Edge location to your system path or use --binary argument.

Grovergroves answered 23/7, 2019 at 18:1 Comment(16)
Add edge location to the edge driver I downloaded?Ulent
Did u try to reinstall it first?Grovergroves
if its not gonna help try to add Edge path to system path.Grovergroves
I did reinstall it but still getting the same errorUlent
u r on windows or mac?Grovergroves
Windows unfortunatelyUlent
Edge should be installed in default location, not the one u created.Grovergroves
Do u know how to add system path?Grovergroves
I think so yes, in the environment variables right?Ulent
The code finds the executable. When it is not finding it clearly says that the executable is not in the path. Anyways, I added it to the path and I am getting the same error as before. I was originally pointing to the location of the path which I believe is no different than adding that same path to environment variables pathUlent
It's says that executable not in the path, if it's can't find driver. In your case its can't find EDGE, u were pointing to driver path, not to Edge path if u r talking about this line- "driver = webdriver.Edge(executable_path = 'C:\\Users\\Downloads\\edgedriver_win32\\msedgedriver.exe')"Grovergroves
What path u were adding to system variable?Grovergroves
I was adding the path to where the exe is stored.Ulent
Something like this - "C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe"?Grovergroves
This is what u need - automationtestinghub.com/…Grovergroves
Let us continue this discussion in chat.Grovergroves
C
0

The Answer by James L is perfectly summarized. I have Microsoft EdgeHTML 18.17763 and I tried to, therefore, run the command:

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

This executed successfully. However, when running my code this time around, I get the error:

Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:52109/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.

Looks like we need to, additionally, also enable developer options in Windows>>Settings>>Developer Options, which, since I do not have admin privileges, I am currently unable to do.

Cross answered 22/1, 2020 at 7:44 Comment(0)
D
0

You must install msedge driver as You do with Chromedriver.

  1. You first check wich version your edge is and then download de Edge driver from Microsoft Page
  2. Download and unzip the msedgedriver file according your browser version
  3. Install the package of it to python in terminal (pip install msedge-selenium-tools selenium==3.141)
  4. Finally try the code to get the browser: from selenium import webdriver

edgeBrowser = webdriver.Edge(r"C:....\msedgedriver.exe") edgeBrowser.get('https://www.google.com')

Doscher answered 9/10, 2022 at 9:38 Comment(0)
B
0

Since Selenium 4.6.0, you don't need to manually install Selenium Manager(webdriver-manager) as shown below because it is already included in Selenium according to the blog:

pip install webdriver-manager

And, since Selenium 4.11.0, the code below is basically enough because Selenium Manager can automatically discover your browser version installed in your machine, then can automatically download the proper driver version for it according to the blog:

from selenium import webdriver

edge_driver = webdriver.Edge()

And, the examples below can test Django Admin with Microsoft Edge, Selenium, pytest-django and Django. *My answer explains how to test Django Admin with multiple Headless browsers(Chrome, Microsoft Edge and Firefox), Selenium, pytest-django and Django:

# "tests/test_1.py"

import pytest
from selenium import webdriver
from django.test import LiveServerTestCase

@pytest.fixture(scope="class")
def edge_driver_init(request):
    edge_driver = webdriver.Edge()
    request.cls.driver = edge_driver
    yield
    edge_driver.close()

@pytest.mark.usefixtures("edge_driver_init")
class Test_URL_Edge(LiveServerTestCase):
    def test_open_url(self):
        self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
        assert "Log in | Django site admin" in self.driver.title

Or:

# "tests/conftest.py"

import pytest
from selenium import webdriver

@pytest.fixture(scope="class")
def edge_driver_init(request):
    edge_driver = webdriver.Edge()
    request.cls.driver = edge_driver
    yield
    edge_driver.close()
# "tests/test_1.py"

import pytest
from django.test import LiveServerTestCase

@pytest.mark.usefixtures("edge_driver_init")
class Test_URL_Edge(LiveServerTestCase):
    def test_open_url(self):
        self.driver.get(("%s%s" % (self.live_server_url, "/admin/")))
        assert "Log in | Django site admin" in self.driver.title
Brasilein answered 5/9, 2023 at 0:53 Comment(1)
if the path to the webdriver is not explicitly set, the executable of pyinstaller would run, it returns "can't find the webdriver"Coletta
B
0
  1. pip uninstall selenium
  2. download stable version https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
  3. unzip folder in c\user\
  4. pip install selenium=4.0
from selenium import webdriver

edge_driver = webdriver.Edge("C:\\Users\\user\\edgedriver\\msedgedriver.exe")
edge_driver.get("https://www.microsoft.com")
Brilliant answered 17/10 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.