Selenium webdriver.Remote无法连接localhost:9999 报错WinError10061怎么办?
解决WinError 10061:Selenium Remote连接Windows计算器失败
WinError 10061本质是目标端口没有服务在监听,你的问题核心是用错了自动化工具的服务端——Selenium Remote默认针对Web浏览器,自动化Windows桌面应用需要用微软官方的WinAppDriver服务,而非普通的Selenium Remote服务。以下是具体解决步骤:
1. 安装Windows Application Driver(WinAppDriver)
WinAppDriver是微软专为Windows桌面应用(UWP、Win32、WPF等)开发的自动化工具,支持计算器这类系统应用,直接从微软官方渠道下载安装即可。
2. 启动WinAppDriver服务
安装完成后,必须先启动WinAppDriver服务:
- 以管理员身份打开命令提示符(CMD)
- 运行命令:
WinAppDriver.exe- 默认情况下,服务会监听
http://localhost:4723端口;如果需要自定义端口,可加参数,比如WinAppDriver.exe 9999(但建议用默认端口避免冲突)
- 默认情况下,服务会监听
- 启动成功后,CMD会显示类似
WinAppDriver listening on http://127.0.0.1:4723的提示,此时服务处于运行状态。
3. 修改代码配置
将代码中的远程连接地址和Capabilities调整为WinAppDriver的要求:
from selenium import webdriver # 初始化驱动连接WinAppDriver driver = webdriver.Remote( command_executor='http://localhost:4723', # 对应WinAppDriver的监听地址 desired_capabilities={ "platformName": "Windows", "deviceName": "WindowsPC", "app": r"C:\Windows\System32\calc.exe", "debugConnectToRunningApp": "false" })
4. 排查连接问题
如果仍出现拒绝连接错误:
- 用命令
netstat -ano | findstr :4723检查端口是否被监听,确认进程ID对应的是WinAppDriver.exe - 确保WinAppDriver是以管理员身份启动的,否则可能无权限访问系统应用
- 检查是否有其他程序占用了4723端口,如有则更换WinAppDriver的监听端口(启动时加端口参数)
内容的提问来源于stack exchange,提问作者Soham Sen
相关产品推荐
相关产品推荐

