Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to select an Iframe by a class name but it's not working , I am trying with tagName it works but then when I tried to type within the element in the Iframe I couldn't, could you please help me here is my code:

webDriver driver.switchTo().frame( driver.findElement( By.className( "cke_wysiwyg_frame cke_reset" ) ) );
driver.findElement( By.xpath( "//body[contains(text(),'type here')]" ) ).sendKeys( "Testing" );

And here is the HTML in my webpage:

<div id="cke_534_contents" class="cke_contents cke_reset" role="presentation" style="height: 75px;">
   <span id="cke_586" class="cke_voice_label">Press ALT 0 for help</span>
   <iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" aria-describedby="cke_586" tabindex="0" allowtransparency="true">
      <!DOCTYPE html>
      <html lang="en-gb" dir="ltr">
         <head>
         <body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="true">
            type here
         </body>
      </html>
   </iframe>
</div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

the problem was solved by finding the iFrame by xpath

driver.switchTo().defaultContent();
driver.switchTo().frame( driver.findElement( By.xpath( iframeXpath ) ) );

and then return to the top window:

 driver.switchTo().defaultContent();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...