简体   繁体   English

python selenium元素不可交互错误

[英]python selenium element not interactable error

I have two input texts我有两个输入文本

<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">

and while using Python Selenium, I accessed each text element and gave out dynamic input values在使用 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)

With the provided code above, I am able to change the first input text value, but not the second one.使用上面提供的代码,我可以更改第一个输入文本值,但不能更改第二个。 This code used to work fine, but it is no longer working and I don't understand what made such change.这段代码曾经可以正常工作,但它不再有效,我不明白是什么造成了这样的变化。 Instead, it is now returning相反,它现在正在返回

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

I confirmed that both the first and second input element is accessible, by printing out elements title.我通过打印元素标题确认第一个和第二个输入元素都可以访问。 So far, I tried setAttribute, executeScript... but none of them worked (or I did some wrongs) (Maybe, it might do something with google chrome auto-updates? it is only thing I can think of right now, )到目前为止,我尝试过 setAttribute、executeScript ......但它们都没有工作(或者我做错了)(也许,它可能会对谷歌浏览器自动更新做些什么?这是我现在唯一能想到的,)

So here is what I have done to solve this issue, Main issue here was (I assume) bad/low internet connections, I added所以这是我为解决这个问题所做的工作,这里的主要问题是(我假设)互联网连接不好/低,我补充说

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

It is still weird that while starting_point_element caused no problem at all, destination input was the only one that caused the problem.奇怪的是,虽然starting_point_element 根本没有引起任何问题,但目的地输入是唯一引起问题的输入。 I also tried with doing nothing with starting point input element and work only with destination point input, destination still caused a problem.我也尝试对起点输入元素不做任何处理,只使用目的地点输入,目的地仍然导致问题。 In reverse (work with starting point only and nothing with destination point), it worked fine.相反(仅使用起点,不使用目标点),它运行良好。 However, after finding a better internet connection, and adding WebDriverWait code as above, I was able to solve the problem, but this seems to be only a temporary solution.但是,在找到更好的互联网连接并添加上述 WebDriverWait 代码后,我能够解决问题,但这似乎只是一个临时解决方案。 Any additional suggestions are welcome.欢迎任何其他建议。

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

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