Saturday 3 June 2017

Working with Frames

  
                                                     Working with Frames


                        A frame is part of the  web page or browser window which leads ans display content independent of its container. Frames allow developers to present HTML pages in multiple views.
                     
Frame example :
                        
                       


HTML Syntax :

<html>
      <frameset cols= "33%,33%,33%">
               <frame name=frame1 id=frame1 src="http://www.flipkart.com"> Frame A
               <frame name=frame2 src="http://www.amazon.com"> Frame B
               <frame name=frame3 src="http://www.jabong.com"> Frame C
      </frameset>
</html>

Locating Frame :
Selenium Webdriver provides three ways of locating a frame element
      1. Index.
      2. Name.
      3. Id.
 
1. Locating Frame using Name attribute :
    Attribute name of the frame element can be used to locate the frame element.   

HTML Sysntax:    
<html>
      <frameset cols= "33%,33%,33%">
               <frame name=frame1 id=frame1 src="http://www.flipkart.com"> Frame A
      </frameset>
</html>

Selenium Code:

WebDriver driver = new FirefoxDriver();
driver.get("file://C:/User/frameset.html");
WebElement frame1= driver.findElement(By.name("frame1"));
driver.switchTo().frame(frame1); // To move on frame
driver.switchTo().defaulltContent(); // To move on main window


    
2. Locating Frame using Id attribute :
    Attribute Id of the frame element can be used to locate the frame element.  

 HTML Sysntax:   
<html>
      <frameset cols= "33%,33%,33%">
               <frame name=frame1 id=frame1 src="http://www.flipkart.com"> Frame A
      </frameset>
</html>

Selenium Code:

WebDriver driver = new FirefoxDriver();
driver.get("file://C:/User/frameset.html");
WebElement frame1= driver.findElement(By.Id("frame1"));
driver.switchTo().frame(frame1); // To move on frame
driver.switchTo().defaulltContent(); // To move on main window

3.  Locating Frame using Index attribute :
     Index value of the frame can be used to locate the frame element. The index  value starts with 0.
     
Selenium Code:

WebDriver driver = new FirefoxDriver();
driver.get("file://C:/User/frameset.html");
driver.switchTo().frame(0); // To move on frame using index
driver.switchTo().defaulltContent(); // To move on main window





No comments:

Post a Comment