Code Trails:
driver.switchTo().defaultContent();
List<WebElement> before = driver.findElements(By.tagName("iframe"));
for (WebElement t : before) {
System.out.println("iframe" + t.getAttribute("src"));
}
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'srcpath')]")));
List<WebElement> after = driver.findElements(By.tagName("iframe"));
for (WebElement t : after) {
System.out.println("iframe" + t.getAttribute("src"));
if(t.getAttribute("src").equalsIgnoreCase("expectedsrc")){
System.out.println("success");
break;
}
}
Before Switching to iframe (let's say abc), iframes above abc were printed which is correct. But after switching, it prints the same iframes. But actually there are different iframes inside the 'abc' iframe. So after switching to abc, it should print iframes which are only inside abc or along with abc iframes.
I didn't get any NoSuchFrameException
while switching which makes it clear that I have switched to the Iframe
.
IFrames doesnot have id
, class
, name
attributes, but src
.
But When I print the PageSource of abc iframe, it prints only the html source of abc iframe.
String pagesrc = driver.switchTo()
.frame(driver.findElement(By.xpath("//iframe[contains(@src,'srcpath')]"))).getPageSource();
Funny, the same code works in Chrome and FF.
Configuration: IEDriverServer: 3.12.0 IEBrowser: IE9 Jar : Selenium 3.4.0 JDK : 1.8
Html Source: Source