Selenium Python: send keys to editable body in iframe

本秂侑毒 提交于 2021-01-29 12:14:11

问题


How is it possible to send keys to an editable body in an iframe?

Page:

<iframe id="description_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area..." src="javascript:&quot;&quot;" style="width: 100%; height: 200px; display: block;"><html><head>...</head><body id="tinymce" class="mce-content-body " data-id="description" contenteditable="true" spellcheck="false" style="min-height: 184px;"><br data-mce-bogus="1"></body></html></iframe>

Code I tried:

description = browser.find_element_by_id('tinymce')
description.click()
description.send_keys("Test")

Error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="tinymce"]"}

回答1:


You should switch to the iframe before sending text.

try,

browser.switch_to_frame(browser.find_element_by_id('description_ifr'))
description = browser.find_element_by_id('tinymce')
description.click()
description.send_keys("Test")


来源:https://stackoverflow.com/questions/57777603/selenium-python-send-keys-to-editable-body-in-iframe

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