0

How do I send keys to 3 TinyMCE fields on the same screen, and the Iframe ID is dynamic using selenium webdriver c#?

The code below works if the id of the frame was not dynamic:

        Driver.SwitchTo().Frame("ea05aa0a-668b-4a08-9770-221262e77b29_ifr");
        Driver.FindElement(By.Id("tinymce")).SendKeys("hello 1");
        Driver.SwitchTo().DefaultContent();

        Driver.SwitchTo().Frame("c45c67ae-d33b-4ec3-be2e-12a6d40b14ab_ifr");
        Driver.FindElement(By.Id("tinymce")).SendKeys("hello 2");
        Driver.SwitchTo().DefaultContent();


        Driver.SwitchTo().Frame("bbfce656-ea5e-4f01-b409-437d0c60e187_ifr");
        Driver.FindElement(By.Id("tinymce")).SendKeys("hello 3");
        Driver.SwitchTo().DefaultContent();

Code field TinyMCE 1:

<div id="mce_44" class="mce-edit-area mce-container mce-panel mce-stack-layout-item" tabindex="-1" hidefocus="1" style="border-width: 1px 0px 0px;">

<iframe id="ea05aa0a-668b-4a08-9770-221262e77b29_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Área de texto formatado. Pressione ALT-F9 para exibir o menu…a exibir a barra de ferramentas ou ALT-0 para exibir a ajuda" style="width: 100%; height: 100px; display: block;">
    #document
        <!DOCTYPE html>
        <html webdriver="true">
            <head></head>
            <body id="tinymce" class="mce-content-body " contenteditable="true" onload="window.parent.tinymce.get('ea05aa0a-668b-4a08-9770-221262e77b29').fire('load');" spellcheck="false"></body>

Thanks!

Subh
  • 4,354
  • 1
  • 13
  • 32

2 Answers2

0

Hi you can try this only if that's the only iFrame on the Page ideally it'll be something like

   IWebElement iFrameElement = driver.findElement(By.Xpath("//*[contains(@class,'edit-  
   area')]/child:::iframe"));
   Driver.SwitchTo().Frame(iFrameElement);

Or Use a Different Xpath Expression to Math the iFrame something like

//*[contains(@class,'edit-area')]/preceding:::iframe[contains(@id,'ifr')]

Hope this helps

Zach
  • 986
  • 7
  • 19
0

Try this code for switching once then, and perform all actions on the frame:

Driver.SwitchTo().Frame(Driver.FindElement(By.Xpath("//iframe[contains(@title, 'Área de texto formatado.')]")));
Subh
  • 4,354
  • 1
  • 13
  • 32