Robot Framework+Selenium启动Edge浏览器但无法打开网站求助
解决Robot Framework SeleniumLibrary启动Edge浏览器超时及身份错误问题
问题场景
在虚拟环境中使用Robot Framework的SeleniumLibrary执行Edge浏览器自动化测试,仅需完成打开Edge并访问Google.com的操作,测试代码如下:
*** Settings *** Library SeleniumLibrary Test Teardown Close All Browsers *** Test Cases *** Open Google in Edge Set Log Level debug Open Browser https://www.google.com Edge Set Log Level info
执行后持续出现以下错误:
[15452:15508:1202/141313.807:ERROR:edge_auth_errors.cc(523)] EDGE_IDENTITY: Get Default OS Account failed: Error: Primary Error: kImplicitSignInFailure, Secondary Error: kAccountProviderFetchError, Platform error: 0, Error string: [15452:15508:1202/141419.321:ERROR:feature_processor_state.cc(42)] Processing error occured: model EdgeUserTopicOnUrlProtobuf failed with CustomInputError, message: ReadTimeoutError: HTTPConnectionPool(host='localhost', port=50997): Read timed out. (read timeout=120)
已确认驱动可正常识别,且尝试过以下方案但未解决:
- 下载最新组织管理版Edge并匹配驱动版本
- 尝试在隐身窗口运行
- 创建浏览器别名后使用
Switch Browser关键字 - 修改Selenium默认浏览器为Edge
- 尝试使用BrowserLibrary但npm安装受阻
- 尝试
Create Webdriver关键字但未成功 - 编写自定义关键字打开Edge
针对性解决方案
1. 添加Edge启动参数禁用身份验证及不必要功能
组织管理的Edge会自动尝试登录企业账户,同时内置的主题分析功能可能触发错误,这些都会阻塞浏览器初始化导致超时。通过Open Browser的desired_capabilities参数添加启动参数,禁用相关功能:
*** Test Cases *** Open Google in Edge Set Log Level debug ${edge_options}= Evaluate from selenium.webdriver.edge.options import Options; options=Options(); options.add_argument("--disable-features=EdgeUserTopics"); options.add_argument("--disable-edge-identity-auth"); options.add_argument("--no-default-browser-check"); options.add_argument("--disable-extensions") module=selenium.webdriver.edge.options Open Browser https://www.google.com Edge desired_capabilities=${edge_options} Set Log Level info
2. 显式指定Edge驱动路径
虚拟环境可能存在路径优先级问题,即使系统能识别驱动,显式指定路径可确保使用匹配版本的驱动:
*** Settings *** Library SeleniumLibrary executable_path=C:/path/to/msedgedriver.exe # 替换为你的驱动实际路径 Test Teardown Close All Browsers *** Test Cases *** Open Google in Edge Set Log Level debug ${edge_options}= Evaluate from selenium.webdriver.edge.options import Options; options=Options(); options.add_argument("--disable-edge-identity-auth") module=selenium.webdriver.edge.options Open Browser https://www.google.com Edge desired_capabilities=${edge_options} Set Log Level info
3. 正确使用Create Webdriver关键字手动初始化
之前使用Create Webdriver未成功大概率是参数配置错误,以下是正确的初始化方式,更可控:
*** Test Cases *** Open Google in Edge Set Log Level debug ${edge_options}= Evaluate from selenium.webdriver.edge.options import Options; options=Options(); options.add_argument("--disable-edge-identity-auth"); options.add_argument("--disable-features=EdgeUserTopics") module=selenium.webdriver.edge.options Create Webdriver Edge options=${edge_options} Go To https://www.google.com Set Log Level info
4. 延长全局超时时间
浏览器初始化过慢会触发超时,可在导入SeleniumLibrary时增加全局超时阈值:
*** Settings *** Library SeleniumLibrary timeout=180 # 延长至180秒 Test Teardown Close All Browsers
内容的提问来源于stack exchange,提问作者user28590595
相关产品推荐
相关产品推荐

