如何通过Selenium python以textarea形式(以HTML标记)添加文本? [英] How can I add a text in textarea form (in HTML tag) by selenium python?
本文介绍了如何通过Selenium python以textarea形式(以HTML标记)添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下HTML代码:
I have this HTML code:
<form class="_b6i0l"><textarea aria-label="Add a comment…" placeholder="Add a comment…" class="_bilrf" autocomplete="off" autocorrect="off" style="height: 18px;"></textarea>
<textarea aria-label="Add a comment…" placeholder="Add a comment…" class="_bilrf" autocomplete="off" autocorrect="off" style="height: 18px;"></textarea>
</form>
我想在字段中写一个文本.但是,发生了此错误:
I want write a text in the filed. But, this error is happened:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <textarea class="_bilrf"> is not reachable by keyboard
我发送文本的代码是:
add_comment_box= WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "textarea._bilrf")))
time.sleep(5)
add_comment_box.send_keys("nice!")
可以帮我吗?
推荐答案
除了send_keys,我们可以使用以下部分:
Rather than send_keys, we can use this section:
driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_css_selector("textarea._bilrf"), "nice!")
这篇关于如何通过Selenium python以textarea形式(以HTML标记)添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文