0

[找到解决方案,见下文]

我正在使用以下 Python 脚本(使用 Python 2.7)打开 Microsoft Edge 并浏览到 www.freelancer.in(使用 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/")

它在我的本地机器上正常工作:Windows Pro 版本 1709,操作系统 16299.125。但是,它在我的虚拟机上不起作用......我不知道为什么,因为我安装了完全相同的 Windows 10 Pro,我使用的是相同的 Microsoft Webdriver.exe (16299.15)。Microsoft WebDriver.exe 似乎正在工作,因为它说:

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

但之后,我收到以下错误:

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

我没有在 Microsoft Edge 中找到任何特定的配置。关于什么可能导致此错误的任何想法?

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

4

3 回答 3

1

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

于 2019-03-28T08:56:50.933 回答
0

错误说明了一切:

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

很明显,webdriver实例没有被调用。因此,您必须将edge_pathargument executable_path一起传递,如下所示:

driver = webdriver.Chrome(executable_path=edge_path)
于 2018-01-11T15:05:30.457 回答
0

我遇到了与 Edge 相同的问题。调用 Edge 浏览器不需要任何特定配置。以下代码应该足以打开它:

from selenium.webdriver import Edge
driver = Edge()

这适用于我在笔记本电脑上的情况,就像你的情况一样 - 但不适用于带有 Win10 的虚拟机......所以我想我们在这里得到了一个可能的模式。

你写你用 Microsoft Webdriver.exe 16299.15 试过了。您也可以尝试microsoft的更新版本 17134 。它对我不起作用,但对你有用。

此外,应该可以直接从您的 Win10 安装中获取 Microsoft Webdriver.exe:设置 → 应用程序 → 管理可选功能 → 添加功能 → Microsoft WebDriver。这应该将 Microsoft Webdriver 直接安装到您的机器上,并将其添加到 PATH。

顺便说一句...如果您在 PATH 中设置了 MicrosoftWebDriver.exe,则不需要通过 edge_path。

于 2019-02-11T10:21:48.663 回答