0

I need to automate the following test: after the login on the web page a new pop-up window (with app) opens and all steps should be done in this new window.

Question: how to code to switch from the current login window to the new pop-up window?

Thank you!

2
  • stackoverflow.com/questions/14939298/… Commented Apr 9, 2020 at 15:50
  • unfortunately, it's not the same case. In my case, I need to change focus to pop up and continue the test in pop-up. Commented Apr 9, 2020 at 16:22

1 Answer 1

1

If you want to handle child window then you have to use handles in seleneium, Kindly refer below code:

String parentWindowHandle = driver.getWindowHandle(); // get the current window handle

//Perform action on your parent window 
//Perform clcik() action on your parent window that opens a new window    

for (String winHandle : driver.getWindowHandles()) {

         if(!winHandle.equals(parentWindowHandle))
         {
            driver.switchTo().window(winHandle); // Here yor switching control to child window so that you can perform action on child window
            System.out.println("Title of the new window: " +
            driver.getTitle());
            //code to do something on new window
            System.out.println("Closing the new window...");
            driver.close();
         }

   }   

driver.switchTo().window(parentWindowHandle);
System.out.println("Parent window URL: " + driver.getCurrentUrl());
Sign up to request clarification or add additional context in comments.

7 Comments

there is a problem. IE closes the parent window (no idea why). sometimes the test works, sometimes it fails with the error NoSuchWindowException: Window is closed in the code line: String parentWindowHandle = driver.getWindowHandle();
what issue are you facing ?
it looks like the app and IE 11 is doing the following: after the log-in in the parent window it opens a new pop-up window and closes the parent one without focus in the new pop-up window. If I add the code you mention above, sometime it works, sometime it does not. Without your code it shows an error: NoSuchWindowException: Unable to get browser.
Check with chrome and firefox because if parent window is closinng on them then you need to raise this with dev team
App is compatible with IE only :( probably I can just modify this driver.switchTo().window(winHandle); without checking the parent window?
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.