If I am inside a inner frame and there is button if I click on that button a new window will open. Will it be possible to switch to newly open window doing driver.switchTo().defaultContent(). ?
2 Answers
You do not need to switch between frames, you do however, need to switch between windows.
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
public class IndexOfIframe {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
// I used http://demo.guru99.com/test/guru99home/
driver.get("http://yourwebsite.com");
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
int size = driver.findElements(By.tagName("iframe")).size();
for(int i=0; i<=size; i++){
driver.switchTo().frame(i);
int total=driver.findElements(By.xpath("html/body/a/img")).size();
System.out.println(total);
driver.switchTo().defaultContent();}}}
-
Why don't you add some explanations on what the code is doing so it is more useful for anyone that might read it? Commented May 28, 2020 at 11:30
-