簡體   English   中英

如何在此 html 中使用 Selenium/Python 編寫一些文本

[英]How do I write some text using Selenium/Python in this html

我正在嘗試在以下字段中插入一些文本,但它說它不可交互

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

send_keys適用於輸入字段:由於您嘗試過div text-appending 它不能那樣工作。

你可以試試這個(使用javascript):

driver.execute_script("document.querySelector('#tagsReview').innerText = 'XYZ';")

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM