我想将文字发送到某个字段并提交。 HTML代码已显示。我应该怎么做? 这是我的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>
我想用以下代码发送文本到框:
driver.execute_script("arguments[0].value = arguments[1]", driver.find_element_by_css_selector("textarea._bilrf"), "nice!")
如何按Enter键发送文字? 你能帮帮我吗?
答案 0 :(得分:3)
尝试使用send_keys()
(https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html#selenium.webdriver.remote.webelement.WebElement.send_keys)和特殊密钥模块(https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html#module-selenium.webdriver.common.keys)
from selenium.webdriver.common.keys import Keys
...
driver.find_element_by_css_selector("textarea._bilrf").send_keys("nice!", Keys.ENTER)
答案 1 :(得分:0)
from selenium.webdriver.common.keys import Keys
a = driver.find_element_by_css_selector("textarea._bilrf").send_keys("nice!")
a.submit()