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

Selenium中如何处理FIDO认证弹窗?

处理FIDO/WebAuthn弹窗的Selenium自动登录方案
  • 用WebAuthn自动化模拟器搞定
    专门的WebAuthn测试工具比如webauthn-simulator能模拟U2F设备交互,启动浏览器时注入扩展或脚本,让浏览器以为有可用设备,自动完成验证。
    操作步骤:

    1. 先拿到对应的扩展文件或者安装相关npm包
    2. 在ChromeOptions里加扩展:
      from selenium import webdriver
      
      options = webdriver.ChromeOptions()
      options.add_extension('webauthn-simulator.crx') # 替换成你的扩展路径
      driver = webdriver.Chrome(options=options)
      
    3. 触发登录后,执行JS调用模拟器API完成验证:
      window.WebAuthnSimulator.createCredential({
        rpId: "webauthn.io",
        userHandle: "你的用户ID",
        userName: "你的用户名"
      });
      
  • 配置Chrome启动参数跳过交互
    部分Chrome启动参数能禁用WebAuthn的用户提示,比如用--user-data-dir加载预配置的用户数据,配合--disable-web-security(仅限测试环境),不过稳定性一般,适合临时测试。

  • 复用浏览器已保存的凭据
    如果你手动登录过一次并让浏览器保存了WebAuthn凭据,启动Selenium时加载同一个用户数据目录,浏览器会自动用已存凭据完成验证,不用碰弹窗。
    示例代码:

    options = webdriver.ChromeOptions()
    # 替换成你的Chrome用户数据实际路径
    options.add_argument(r"user-data-dir=C:\Users\你的用户名\AppData\Local\Google\Chrome\User Data")
    options.add_argument("--profile-directory=Default")
    driver = webdriver.Chrome(options=options)
    
  • 桌面自动化工具凑合用
    临时场景可以用PyAutoGUI模拟鼠标点击弹窗选项,缺点是依赖屏幕坐标和按钮样式,分辨率变了就失效。
    示例:

    import pyautogui
    import time
    
    # 触发登录后等弹窗出来
    time.sleep(2)
    # 用截图定位"允许"按钮并点击(提前截好按钮图)
    pyautogui.click(pyautogui.locateCenterOnScreen('allow_btn.png'))
    

内容的提问来源于stack exchange,提问作者Eusden Lin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.23 06:06:17