Python script can't open Microsoft edge

4.8k views Asked by At

[Solution found, see below]

I am working with the following Python script (using Python 2.7) to open Microsoft Edge and browse to www.freelancer.in (using Selenium 3.8.1):

import os
from selenium import webdriver

# create new Edge session
dir = os.path.dirname(__file__)
edge_path = dir + "\MicrosoftWebDriver.exe"
driver = webdriver.Edge(edge_path)
driver.implicitly_wait(10)

driver.get("https://www.freelancer.in/")

It works properly on my local machine: Windows Pro Version 1709, OS 16299.125. However, it does not work on my virtual machine... I can't figure out why because I have the exact same Windows 10 Pro installed, I am using the same Microsoft Webdriver.exe (16299.15). The Microsoft WebDriver.exe seems to be working since it says:

[15:32:45.548] - Listening on http://localhost:17556/

But after, I receive the following error:

Traceback (most recent call last):
  File "C:\Users\program.py", line 9, in <module>
    driver = webdriver.Edge(edge_path)
  File "C:\Python27\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 43, in __init__
    desired_capabilities=capabilities)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
    raise exception_class(value)
WebDriverException: Message: Unknown error

I didn't find any specific config to do in Microsoft Edge. Any ideas of what could be responsible for this error?

=> Solution found there : selenium.common.exceptions.WebDriverException: Message: Unknown error while trying to use Edge and MicrosoftWebDriver.exe through Selenium It was not working on the virtual machine because the User Account Control settings were Turned off... Turned on UAC resolved the issue.

3

There are 3 answers

0
Antoine M. On BEST ANSWER

=> Solution found there : selenium.common.exceptions.WebDriverException: Message: Unknown error while trying to use Edge and MicrosoftWebDriver.exe through Selenium It was not working on the virtual machine because the User Account Control settings were Turned off... Turned on UAC resolved the issue.

2
undetected Selenium On

The error says it all :

selenium.common.exceptions.WebDriverException: Message: Unknown error

It's pretty clear that the webdriver instance is not getting invoked. So you have to pass the edge_path along with the argument executable_path as follows :

driver = webdriver.Chrome(executable_path=edge_path)
0
krupaluke On

I got identical issue with Edge. There should not be any specific configuration required for invoking Edge browser. Following code should be enough for opening it:

from selenium.webdriver import Edge
driver = Edge()

This works ok for me on laptop as in your case - but not on virtual machine with Win10... so I guess we got a possible pattern here.

You wrote you tried it with Microsoft Webdriver.exe 16299.15. You can try also newer version 17134 from microsoft. It did not work for me but could for you.

Also there is supposed to be possible to get Microsoft Webdriver.exe directly from your Win10 installation: Settings → Apps → Manage optional features → Add a feature → Microsoft WebDriver. This should install Microsoft Webdriver directly to your machine plus add it to PATH.

Btw... edge_path is not needed to pass if you got MicrosoftWebDriver.exe set in PATH.