Python 3.x 如何通过selenium python在textarea表单(HTML标记)中添加文本?
我有以下HTML代码:Python 3.x 如何通过selenium python在textarea表单(HTML标记)中添加文本?,python-3.x,selenium,selenium-webdriver,textarea,sendkeys,Python 3.x,Selenium,Selenium Webdriver,Textarea,Sendkeys,我有以下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…" place
<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>
您能帮我吗?我们可以使用此部分,而不是发送密钥:
driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_css_selector("textarea._bilrf"), "nice!")
表单中有2个文本区域吗?没有,只有一个。@hamed baziyad,您的帖子中的HTML有2个
textarea
@hamed baziyad,请尝试使用其他驱动程序。如果它起作用,那就是司机的问题。如果不是,则您选择了错误的元素,或者这是一个时间问题,在这种情况下,您应该使用服务员等待预期的状态,或者如果无法获得状态,则无异常。@hamed baziyad,通过直接设置该值,您不再发出页面可能依赖的事件。因此,您不再模拟来自用户的输入。如果您正在抓取/自动化页面,这可能是正常的,但如果您正在测试页面,则情况并非如此。请注意,您的帖子不太可能有用,因为我们仍然不知道为什么硒元素被认为是不可相互作用的。
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!")
driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_css_selector("textarea._bilrf"), "nice!")