我正在尝试在 here 的文本框中写入内容。这个框的右侧写着“将您的文本粘贴到此处”。
我想我的问题是如何找到我应该在 selenium 驱动程序中发送文本的框的项目,例如通过 id?
我尝试过类似的方法:
item = driver.find_element_by_css_selector("form#text_processor input[name=process_this]")
item.send_key("Test!")
但是当我这样做时,我收到此错误消息:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":"form#text_processor input[name=process_this]"}
非常感谢您对此提供的任何帮助。
最佳答案
文本区域位于 iframe
内 - 切换到它,找到元素并向其发送键:
driver.switch_to.frame("textarea_iframe")
driver.find_element(By.ID, "textarea_body").send_keys("test")
<小时/>
请注意,要删除文本区域中的现有文本,只需将其全部预选即可:
text_area = driver.find_element(By.ID, "textarea_body")
text_area.send_keys(Keys.CONTROL, "a") # or Keys.COMMAND on Mac
text_area.send_keys("test")
<小时/>
此外,如果您需要返回主要内容,请使用:
driver.switch_to.default_content()
关于Python:Selenium 在表单的文本框中写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33062149/