首页 > 解决方案 > 如何在这个 html 中使用 Selenium/Python 编写一些文本

问题描述

我正在尝试在以下字段中插入一些文本,但它说它不可交互

<div class="col-md-6">
<div id="tagsReview" class="p4-autocomplete" style="width: 179px; border-radius: 4px;">
<ul class="p4-autocomplete-labels"></ul><input type="text"><ul class="p4-autocomplete-suggestions" style="width: 179px; display: none;">
<li class="newItem selected"><a>Criar novo marcador</a></li>
</div>

我尝试了不同的方法,但都没有奏效。

有任何想法吗?谢!

编辑:

此代码可在文本字段中单击: driver.find_element_by_id('tagsReview').click()

向该 ID 发送密钥不起作用:

driver.find_element_by_id('tagsReview').send_keys('xyz')
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=83.0.4103.61)

其他尝试:

driver.find_element_by_xpath("(//*[contains(@class,'p4-autocomplete')])").send_keys('xyz')
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=83.0.4103.61)

driver.find_element_by_class_name('p4-autocomplete-labels').click()
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=83.0.4103.61)

driver.find_element_by_class_name('p4-autocomplete').click()
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div id="tagsSearch" class="p4-autocomplete" style="float: right; margin-top: -5px; width: 179px;">...</div> is not clickable at point (1254, 224). Other element would receive the click: <div id="dlgCreateNextReview" class="modal in" tabindex="-1" style="display: block;">...</div>
  (Session info: chrome=83.0.4103.61)

标签: pythonseleniumtextinsertselenium-chromedriver

解决方案


我刚刚用 driver.find_element_by_xpath("//*[@id='tagsReview']/input") 解决了


推荐阅读