driver is failing to switch to default content

Viewed 24

So I am able to send keys to the input box in the iframe but my script fails once it gets to driver.switch.to.default_content()

try: 
    # iframe/textbox 
    iframe = driver.find_element(By. XPATH, "/html/body/div[3]/div[4]/div/nz-modal-container/div/div/div[2]/div[2]/nz-form-item[1]/nz-form-control/div/div/app-richtext/div/div[2]/div[1]/div[2]/div[1]/iframe")
    driver.switch_to.frame(iframe)
    time.sleep(2)
    driver.find_element(By. XPATH, "/html/body/p").send_keys('Test')
    driver.switch_to.default_content()
   
    
    #....
    driver.find_element(By. CSS_SELECTOR, "#cdk-overlay-9 > nz-modal-container > div > div > div.ant-modal-footer.ng-tns-c101-267.ng-star-inserted > button.ant-btn.orange.ant-btn-primary.ng-star-inserted").click()

the iframe is nested in a div, but the div is inside of the body tag so I do not understand why it keeps failing.

<div class="tox-sidebar-wrap"><div class="tox-edit-area"><iframe id="tinymceEditor25143_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area. Press ALT-0 for help." class="tox-edit-area__iframe" cd_frame_id_="e4e847880825311ca786ccd99c5e96d0"></iframe></div><div role="complementary" class="tox-sidebar"><div data-alloy-tabstop="true" tabindex="-1" class="tox-sidebar__slider tox-sidebar--sliding-closed" style="width: 0px;"><div class="tox-sidebar__pane-container"></div></div></div></div>
<div class="tox-edit-area"><iframe id="tinymceEditor25143_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area. Press ALT-0 for help." class="tox-edit-area__iframe" cd_frame_id_="e4e847880825311ca786ccd99c5e96d0"></iframe></div>
        

<iframe id="tinymceEditor25143_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area. Press ALT-0 for help." class="tox-edit-area__iframe" cd_frame_id_="e4e847880825311ca786ccd99c5e96d0"></iframe>
0 Answers
Related