【发布时间】:2021-06-09 21:09:24
【问题描述】:
[找到解决方案,见下文]
我正在使用以下 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: Message: Unknown error while trying to use Edge and MicrosoftWebDriver.exe through Selenium 它无法在虚拟机上运行,因为用户帐户控制设置已关闭...打开 UAC 解决了该问题。
【问题讨论】:
-
你用其他浏览器试过吗?是否需要边缘?
-
嗨,我的目标是在所有可能的网络浏览器上自动测试应用程序,我使用的是 Robot Framework 及其 Selenium 库,我对其他浏览器没有任何问题,它只是不适用于边缘。我在 python 中编写了这个脚本,以查看问题是否与机器人框架相关(看起来不是)。
标签: python selenium selenium-webdriver microsoft-edge microsoft-webdriver