I have written a code to click on a textarea inside a form. To clear content of the text area and write a new text I have to go into that iframe
. I am able to clear content and write a new text but unable to click on submit or cancel button which is not inside that iframe
(apparently outside of iframe
)
I have tried using driver.switch_to.parent_frame()
and driver.switch_to.default_content()
but using these two commands my webdriver
restart and closes. I have also tried using
currentWindow = driver.current_window_handle;
driver.switch_to.window(currentWindow)
Here is my code
currentWindow = driver.current_window_handle;
KeyMessage_Input = driver.find_element(By.XPATH, "//div[@id='id_Message']").click()
time.sleep(3)
iframe = driver.find_element(By.CLASS_NAME,"wysihtml5-sandbox")
# Switch to the iframe context
driver.switch_to.frame(iframe)
textbox = driver.find_element(By.TAG_NAME,"body")
textbox.click()
# Clear the textbox contents
textbox.clear()
#time.sleep(2)
textbox.send_keys("This is Key Message")
time.sleep(3)
driver.switch_to.window(currentWindow)
Here is html code:
<textarea id="textarea_1677326708786" class="editable-wysihtml5" style="display: none;"></textarea>
<iframe class="wysihtml5-sandbox" security="restricted" allowtransparency="true" frameborder="0" width="0" height="0" marginwidth="0" marginheight="0" style="display: inline-block; background-color: rgb(255, 255, 255); border-collapse: separate; border-color: rgb(118, 118, 118); border-style: solid; border-width: 0.8px; clear: none; float: none; margin: 0px; outline: rgb(0, 0, 0) none 0px; outline-offset: 0px; padding: 2px; position: static; inset: auto; z-index: auto; vertical-align: baseline; text-align: start; box-sizing: border-box; box-shadow: none; border-radius: 0px; width: 566px; height: 250px;"></iframe>
for submit and cancel button
<div class="editable-buttons"><button type="submit" class="btn btn-primary btn-sm editable-submit"><i class="fa fa-check" aria-hidden="true"></i></button><button type="button" class="btn btn-default btn-sm editable-cancel"><i class="fa fa-times" aria-hidden="true"></i></button></div>