0

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(). ?

1
  • yes,you need to directly switch at child window. Commented May 1, 2019 at 14:48

2 Answers 2

1

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);     
 } 
0
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();}}}
2
  • Why don't you add some explanations on what the code is doing so it is more useful for anyone that might read it?
    – Mate Mrše
    Commented May 28, 2020 at 11:30
  • yes it make seance Commented May 30, 2020 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.