How to apply wait for new window using Selenium WebDriver

0 votes
How to apply wait for new window using Selenium WebDriver?
Jul 9, 2019 in Selenium by Manav

1 answer to this question.

0 votes

As sometimes during web automation, when you perform click on a particular hyper link, it opens up a new window. In this post I will explain how to apply wait for a new window until it gets open as-

public class WaitForNewWindow {


public void testApp() {

     WebDriver driver = new ChromeDriver();

     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);



     //Verify new window is opened or not

    Assert.assertTrue(waitForNewWindow(driver,10), "New window is not opened");

     System.out.println("New window has been opened");



  public boolean waitForNewWindow(WebDriver driver, int timeout){

          boolean flag = false;

          int counter = 0;


              try {

                  Set<String> winId = driver.getWindowHandles();

                  if(winId.size() > 1){

                      flag = true;

                      return flag;




                  if(counter > timeout){

                      return flag;


              } catch (Exception e) {


                  return false;



          return flag;



answered Jul 10, 2019 by Vaishali Walia

Hi Vaishali, that's an exactly copied answer from here:

Can you share any other answer of your own to explain the answer better?

Related Questions In Selenium

0 votes
1 answer

Wait for an element to be accessible using Selenium WebDriver

You can try out the below code: ...READ MORE

answered May 18, 2018 in Selenium by Atul
• 10,230 points
0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

How to I switch to a new window for links with “blank” targets using Capybara?

Capybara 2.3 includes the new window management ...READ MORE

answered Jul 11, 2018 in Selenium by Meci Matt
• 9,460 points
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 14, 2020 in Selenium by Gitika
• 65,970 points
0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 29, 2018 in Selenium by bug_seeker
• 15,550 points
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
1 answer

Impilicit wait vs Explicit wait vs Fluent wait

Implicit wait: Your telling the WebDriver the ...READ MORE

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points