简体   繁体   中英

Python script can't open Microsoft edge

[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.

=> 在那里找到解决方案:selenium.common.exceptions.WebDriverException:消息:尝试通过 Selenium 使用 Edge 和 MicrosoftWebDriver.exe 时出现未知错误 它在虚拟机上不起作用,因为用户帐户控制设置已关闭...已关闭在 UAC 上解决了这个问题。

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM