如何通过 selenium python 添加 textarea 形式的文本(在 HTML 标签中)?

How can I add a text in textarea form (in HTML tag) by selenium python?

我有这个 HTML 代码:

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

我想在字段中写一段文字。但是,发生了这个错误:

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,我们可以使用此部分:

driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_css_selector("textarea._bilrf"), "nice!")