I went through a few posts on SO and used the suggested approach of switching to the iframe -
driver.switch_to.frame(driver.find_element_by_id(iFrameID))
element = driver.find_element_by_xpath('HTML/BODY')
However, I get a NoSuchElementException for the find by xpath.
I then added a print (driver.page_source) after switching to the iframe, and saw the following structure -
<HTML dir=ltr><HEAD><LINK rel=stylesheet type=text/css
href="/_layouts/1033/styles/core.css">
<META name=GENERATOR content="MSHTML 11.00.9600.18639"></HEAD>
<BODY class=ms-formbody contentEditable=true style="BORDER-TOP: medium none;
BORDER-RIGHT: medium none; BORDER-BOTTOM: medium none; BORDER-LEFT: medium
none; BACKGROUND-COLOR: white" scroll=yes WebLocale="1033"
BaseElementID="baseTextField" wordWrap="false" RestrictedMode="true">
<DIV></DIV></BODY></HTML>
The HTML/BODY structure is definitely present so I'm not sure what I'm doing wrong in the find_element_by_xpath. I also tried /HTML/BODY and//HTML/BODY with no luck.
As a workaround, I tried to bring the RTE into focus by clicking the iframe and then using ActionChains
driver.find_element_by_id(iFrameID).click()
actions = ActionChains(driver)
actions.send_keys("Lorem Ipsum")
actions.perform()
But got the following error:
NameError: name ActionChains is not defined
Any help would be appreciated
from selenium.webdriver import ActionChains<iframe>tag you are trying to switch to? The output ofdriver.page_sourcehas been truncated. Stop relying on that method... it's inconsistent and doesn't do what you think it does. @AzatIbrakov he is trying to switch to aniframe, he first encountered the lib import as you pointed out. But, he still will get theNoSuchElementExceptionerror for thedriver.find_element_by_id(iFrameID).click()command.iframeand sent text toActionChains()instance!? Share what exactly you want to do as for now your logic is quite unclear