繁体   English   中英

python selenium元素不可交互错误

[英]python selenium element not interactable error

我有两个输入文本

<input id="info.route.waypointSuggest.input0" title="search input1" class="input" type="text" autocomplete="off">
<input id="info.route.waypointSuggest.input1" title="search input2" class="input" type="text" autocomplete="off">

在使用 Python Selenium 时,我访问了每个文本元素并给出了动态输入值

starting_point_path = '//*[@id="info.route.waypointSuggest.input0"]'
starting_point_element = web.find_elements_by_xpath(starting_point_path)
starting_point = input('first\n')
starting_point_element[0].send_keys(starting_point)
starting_point_element[0].submit()
time.sleep(3)
destination_path = '//*[@id="info.route.waypointSuggest.input1"]'
destination_element = web.find_elements_by_xpath(destination_path)
destination = input('second\n')
destination_element[0].send_keys(destination)
destination_element[0].submit()
time.sleep(3)

使用上面提供的代码,我可以更改第一个输入文本值,但不能更改第二个。 这段代码曾经可以正常工作,但它不再有效,我不明白是什么造成了这样的变化。 相反,它现在正在返回

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=80.0.3987.132)

我通过打印元素标题确认第一个和第二个输入元素都可以访问。 到目前为止,我尝试过 setAttribute、executeScript ......但它们都没有工作(或者我做错了)(也许,它可能会对谷歌浏览器自动更新做些什么?这是我现在唯一能想到的,)

所以这是我为解决这个问题所做的工作,这里的主要问题是(我假设)互联网连接不好/低,我补充说

WebDriverWait(web, 4).until(EC.visibility_of_element_located((By.XPATH, destination_path)))

奇怪的是,虽然starting_point_element 根本没有引起任何问题,但目的地输入是唯一引起问题的输入。 我也尝试对起点输入元素不做任何处理,只使用目的地点输入,目的地仍然导致问题。 相反(仅使用起点,不使用目标点),它运行良好。 但是,在找到更好的互联网连接并添加上述 WebDriverWait 代码后,我能够解决问题,但这似乎只是一个临时解决方案。 欢迎任何其他建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM