How can I add a text in textarea by selenium python?

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

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 

My code which sends the text is:

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

Could you help me, please?

回答1:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!