簡體   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