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

使用Python SeleniumBase在网页文本框输入MRI失败,请求排查

问题排查与修复方案

你的代码执行失败的核心原因是定位选择器错误:你用了input#Procedure来定位元素,但目标输入框并没有id="Procedure"这个属性,导致SeleniumBase找不到对应元素。

修复步骤:

  1. 从你提供的元素HTML截图来看,目标输入框具备placeholder="Procedure"和name="procedure"这类可用于定位的属性,选择这些属性替换错误的ID选择器即可。
  2. 建议先等待元素加载完成再执行输入操作,避免页面未渲染完成导致的定位失败。

修改后的代码:

from seleniumbase import BaseCase

class HealthSiteTest(BaseCase):
    def test_health_site(self):
        self.open("https://www.finestrahealth.com/")
        self.assert_element_present("Finestra")
        # 使用placeholder属性定位输入框,等待元素加载后输入
        self.wait_for_element_present('input[placeholder="Procedure"]')
        self.type('input[placeholder="Procedure"]', "MRI")

if __name__ == "__main__":
    from pytest import main
    main([__file__])

其他可选定位方式:

  • 用name属性:self.type('input[name="procedure"]', "MRI")
  • 用class属性(需确认class唯一):self.type('input.form-control', "MRI")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 04:02:58