Sorry my previous reply (which wasn't tested fully):
Below is the working code : (i)
When the iframe is directly inside the body tag
for example: <link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="signin.css">
</head>
<body>
<iframe src="http://www.w3schools.com"></iframe>
<div class="header" ng-controller="repLoginCtrl as repLoginCtrl">
<header class="container-fluid">
<div class="content"></div>
</header>
<div class="page-title">
public static void main(String[] arg) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/myhtml.html");
List<WebElement> elements = driver.findElements(By.tagName("iframe"));
WebElement element = null;
for(WebElement ele: elements)
{
if(ele.getAttribute("src").contains("
http://www.w3schools.com"))
{
element = ele;
break;
}
}
driver.switchTo().frame(element);
new WebDriverWait(driver, 60).until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//a[contains(@title, 'Translate W3Schools')]"))));
System.err.println("href attribute value : "+ driver.findElement(By.xpath("//a[contains(@href, '
http://www.w3schools.com')]")).getAttribute("href"));
System.out.println("\n");
driver.findElement(By.xpath("//a[contains(@title, 'Translate W3Schools')]")).click();