Python Selenium,Input字段返回ElementNotInteractiableException,即使



已解决:

除非在最近的0.1秒内单击,否则这个单个输入字段似乎是不可交互的。为了解决这个问题,使用了以下代码:

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

这样,焦点就停留在元素上,输入就起作用了。有趣的是,如果调用input.send_keys(),这仍然不起作用。

问题:

按下网站上的按钮后,会打开一个弹出窗口,其中包含由react生成的多个输入字段。其中大部分是可访问的。但是,其中一个不是,并返回ElementNotInteractiableException错误。我尝试过最常见的解决方案,但都不起作用。

有趣的是,当从前端手动访问元素时,可以与之交互。该元素也通常显示在屏幕截图中,该屏幕截图是在抛出异常时拍摄的

尝试的解决方案:

  • 增加隐含等待直到1分钟
  • 添加显式等待直到1分钟
  • 对元素使用不同的查找方法
  • 重新排序测试,看看其他因素是否会影响它(所有可能的订单都失败了)
  • 添加操作链移动到并单击。移动到并单击工作(我可以看到用蓝色轮廓选择的元素,但输入仍然感觉良好)
  • 使用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")

错误日志:

https://pastebin.com/ihqCvjfj

它很长,但它是一个非常标准的元素——不可访问的

任何建议都将不胜感激,每当我尝试时,我都会更新已尝试的解决方案部分

当元素不在可点击区域或其他元素覆盖该元素时,就会出现不可交互的元素。您可以尝试将页面滚动到一个元素,也可以通过执行javascript来设置输入值,比如:

element = inputparent.find_element_by_css_selector("input")
driver.execute_script("""arguments[0].value = arguments[1];""", element, "some input value") 

相关内容

  • 没有找到相关文章

最新更新