You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell调用MS Edge实现网站自动登录出现报错如何解决?

故障原因

Microsoft Edge 不支持传统 IE 公开的 COM 自动化接口,New-Object -ComObject 'internetExplorer.Application' 仅能调用 IE 程序,不存在对应的 Edge COM 组件,因此会触发类未注册、空对象调用等报错。

可行解决方案

方案1:Edge IE 模式复用原有代码(改动最小)

该方案可以完全复用你之前写的 IE 自动化代码,不需要调整逻辑,仅需提前配置 Edge 兼容规则:

  1. 打开 Edge 设置 -> 默认浏览器,将「允许在 Internet Explorer 模式下重新加载网站」设置为允许
  2. 点击「Internet Explorer 模式页面」下方的「添加」,将目标登录站点的域名添加到列表中
  3. 直接运行你之前的 IE 自动登录 PowerShell 代码即可,站点会自动在 Edge 的 IE 兼容模式下加载,登录逻辑完全可用。

方案2:Edge WebDriver 实现原生 Edge 自动化(官方推荐,长期兼容)

该方案完全基于 Edge 原生能力实现自动化,不需要依赖 IE 组件,适合长期使用的场景:

  1. 首先查看当前 Edge 版本(地址栏输入 edge://settings/help 即可查看),下载对应版本的 Edge WebDriver 程序,将解压后的 msedgedriver.exe 放入系统 PATH 路径,或者在脚本中指定其路径。
  2. 以管理员身份运行 PowerShell,执行命令安装 Selenium 模块:
    Install-Module Selenium
  3. 替换原有代码为以下实现即可:
# 导入Selenium模块
Import-Module Selenium

# 启动Edge实例
$driver = Start-SeEdge
# 打开目标登录页面
$driver.Url = "https://www.tibia.com/mmorpg/free-multiplayer-online-role-playing-game.php"

# 等待页面加载完成
Start-Sleep -Seconds 3

# 配置登录凭证
$username = "myname"
$RSAPIN = "mypin"
$password = "mypassword"

# 填充登录表单
Send-SeKeys -Element (Find-SeElement -Driver $driver -Id 'username') -Keys $username
Send-SeKeys -Element (Find-SeElement -Driver $driver -Id 'password_input') -Keys $RSAPIN
Send-SeKeys -Element (Find-SeElement -Driver $driver -Id 'secondary_password_input') -Keys $password

# 如需自动点击登录按钮,可取消下行注释,替换为实际登录按钮的元素ID即可
# Click-SeElement -Element (Find-SeElement -Driver $driver -Id 'login_button_id')

内容的提问来源于stack exchange,提问作者John R Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 13:30:03