My Blog List

Monday, November 14, 2011

Selenium - Handle Iframes/Frames easily

Hi all,
Here I am going to list out ways to handle iFrames parts in selenium automation as I read from some sites.
Example-1:


  1. //Gmail Body is an iframe. Here we are writing content to body of new mail in selenium
  2. var bodytext="Sample Body Text for Testing";  
  3. var iframe_locator = "css=table:contains('Subject:') +*  iframe\";
  4. var iframe_body = selenium.browserbot.findElement(iframe_locator).contentWindow.document.body;
  5. if (browserVersion.isChrome) {    
  6.   iframe_body.textContent=bodytext;
  7. }  else if(browserVersion.isIE) {
  8.   iframe_body.innerText=bodytext;
  9. }

Example-2:

  1. //Switch to the frame - use index/name
  2. driver.switchTo().frame("frameName"); 
  3. //Also you can use like 
    SwitchTo.Frame(relative=up)
    SwitchTo.Frame(relative=top)

    // Do your operations in frame 
  4. //Switch back to the parent window
  5. driver.switchTo().defaultContent();





1 comment:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete