Hi,
Though I have tried my be but was unable to find a proper solution for the problem using explicit wait functionality .
Mean wile I propose you a solution using Thread.sleep for the above snippet .
Issue 1: In your code no where it was indicated to switch out from frame1 ,as frame2 not a part of the fram1.
Resolution: I have used
driver.switchTo().defaultContent();
for switching to default or main document where web contents are situated.
Issue 2: After switching to main web page , the code has not given enough time to identify and locate frame2.
Resolution: I have used
Thread.sleep(3000);
where 3000 indicates the dimension of time (milliseconds)
And now your code is working fine.
I have uploaded the image in the following link:
[
^]
Code as followed:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class codeproject {
WebDriver driver;
@Test
public void function() throws InterruptedException{
System.setProperty("webdriver.chrome.driver","D:\\training\\DB_Study_selenium\\class7 _ webdrider\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("http://only-testing-blog.blogspot.in/2015/01/iframe1.html");
int size = driver.findElements(By.tagName("iframe")).size();
System.out.println("total frames"+size);
driver.switchTo().frame("frame1");
driver.findElement(By.xpath(".//*[@id='post-body-3107268830657760720']/div[1]/table/tbody/tr[1]/td[1]/input")).click();
driver.findElement(By.xpath(".//*[@id='post-body-3107268830657760720']/div[1]/table/tbody/tr[2]/td[2]/input")).click();
driver.findElement(By.xpath(".//*[@id='post-body-3107268830657760720']/div[1]/table/tbody/tr[3]/td[1]/input")).click();
driver.findElement(By.xpath(".//*[@id='post-body-3107268830657760720']/div[1]/table/tbody/tr[4]/td[2]/input")).click();
driver.findElement(By.xpath(".//*[@id='post-body-3107268830657760720']/div[1]/table/tbody/tr[5]/td[1]/input")).click();
driver.switchTo().defaultContent();
System.out.println("default content");
Thread.sleep(5000);
System.out.println("Initiate for frame 2");
driver.switchTo().frame("frame2");
System.out.println("switch to frame2");
driver.findElement(By.name("fname")).sendKeys("RAM");
System.out.println("2222222222222222222");
driver.findElement(By.id("text3")).sendKeys("GOPAL");
driver.findElement(By.id("check3")).click();
driver.findElement(By.id("radio2")).click();
driver.findElement(By.xpath(".//*[@id='post-body-4292417847084983089']/div[1]/form[1]/input[10]")).click();
WebElement fileInput = driver.findElement(By.name("img"));
fileInput.sendKeys("C:/path/to/file.jpg");
}
}