Tuesday, 29 December 2015

Working on Multiple Frames

package abcpack;

import static org.junit.Assert.assertEquals;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class MultiFrame {
    WebDriver d;
    @Test
    public void testMultiFrame() throws Exception
    {
        //Load the web page
        d.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
        assertEquals("Overview",d.getTitle());
        List<WebElement> f=d.findElements(By.tagName("frame"));
        System.out.println("No of frames:"+f.size());
        //Switch driver focus to 1st frame
        d.switchTo().frame(0);
        d.findElement(By.linkText("com.thoughtworks.selenium")).click();
        d.switchTo().defaultContent();
        //Switch driver focus to 2nd frame
        d.switchTo().frame(1);
        d.findElement(By.linkText("Selenium")).click();
        d.switchTo().defaultContent();
        //Switch driver focus to 3rd frame
        d.switchTo().frame(2);
        assertEquals("Interface Selenium",d.findElement(By.className("title")).getText());
       
        Thread.sleep(4000);
    }
    @Before
    public void setUp()
    {
        //Launch browser
        d=new FirefoxDriver();
         d.manage().window().maximize();
        d.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    }
    @After
    public void tearDown()
    {
        //Close browser
        d.quit();
    }


}

No comments:

Post a Comment