Saturday, 28 September 2013

How to click on elements in i frame using Selenium web driver?

package learing;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class IframeTest {

  public static void main(String[] args) throws InterruptedException {

  WebDriver driver = new FirefoxDriver();
  driver.manage().window().maximize();

  driver.get("http://tinyurl.com/cb3lbho");
  Thread.sleep(5000L);

  try {

    List<WebElement> AlliFrameID = driver.findElements(By.tagName("iframe"));
   System.out.println(AlliFrameID.size());
   for(int i=0;i<=AlliFrameID.size();i++){
    System.out.println(AlliFrameID.get(i).getAttribute("id"));
   }
  } catch (Exception e) {

 driver.switchTo().frame("ifrm");

 driver.findElement(By.xpath("//*[@id='ifrmTest']/p[2]/input")).click();
   System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));

   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
    System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));


   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
   System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));

   driver.findElement(By.xpath("//*[@id='ifrmTest']/p[3]/input")).click();
    System.out.println(driver.findElement(By.xpath("//*[@id='ifrmTest']/p[1]/input")).getAttribute("value"));


   driver.switchTo().defaultContent();
     driver.findElement(By.xpath("//*[@id='testForm']/p/input[1]")).sendKeys("Online selenium Training");

     driver.findElement(By.xpath("//*[@id='testForm']/p/input[2]")).click();

   }

  }

}

2 comments:

  1. Hi Reddy Nice blog.Really it is helping for the people who are new to selenium.Thanks alot.keep up the good work

    ReplyDelete

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...