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

Python Selenium操作React输入框报ElementNotInteractableException解决

已解决

经排查,该输入框仅在最近0.1秒内被点击的状态下才可交互,采用如下代码即可解决:

ActionChains(self.driver).move_to_element(input).click().send_keys("200").perform()

该方案可保持元素持续处于聚焦状态,输入功能正常运行。值得注意的是,直接调用input.send_keys()方法仍然无法生效。

问题描述

点击网站按钮后会弹出由React生成的弹窗,弹窗内包含多个输入框,大部分可正常访问,但其中一个输入框调用输入方法时会抛出ElementNotInteractableException异常,常用解决方案均无效。

特殊现象:手动在前端操作该元素可正常交互,抛出异常时截取的页面截图也显示该元素显示正常。

已尝试的解决方案

  • 将隐式等待时长延长至1分钟
  • 添加最长1分钟的显式等待
  • 使用多种不同的元素定位方式查找目标元素
  • 调整测试用例执行顺序验证是否受其他元素影响,所有排序均测试无效
  • 使用ActionChains执行移动到元素并点击的操作,可观察到元素出现蓝色选中边框,但输入仍然失败
  • 使用Javascript直接向输入框的value属性插入文本

报错对应的代码段

#this input element is next to it in the same parent element
dropdownparent = elems[2].find_element_by_xpath(".//div[@role='combobox']")
dropdowninput = dropdownparent.find_element_by_css_selector("input")
f.inputtext(dropdowninput, "Coulance", True )
#reobtain the parent items to avoid a stale element reference error
modal = self.driver.find_element_by_class_name("component-window")
body = modal.find_element_by_class_name("body")
elems = body.find_elements_by_xpath("./div")
required = elems[2].find_elements_by_class_name("required")
inputparent = required[1].find_element_by_class_name("input")
input = inputparent.find_element_by_css_selector("input")
#error occurs on next line
f.inputtext(input, "200")

错误日志

日志较长,为标准的元素不可访问报错。

欢迎提供其他可行思路,尝试新方案后我会更新已尝试解决方案部分。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 17:45:05