Popup window handling




//Getting the Current window handle in form of string (Note : Output will be for current window and will be in form of immutable String)
String winHandle = driver.getWindowHandle();
 System.out.println("Current Page handle is : " + winHandle );
//Getting the handles for all the windows of the current website via java.util.Set  in form of collection(Note : Output will be for all the windows  and will be in form of Set{Collection})
java.util.Set winHandles = driver.getWindowHandles();
System.out.println(windows.size()); //Output for the number of windows
 

 

Sample Working code for Naukri.com where we are closing all extra windows and getting back to main window:
public static void main(String[] args) {
         WebDriver driver = new ChromeDriver();
        driver.get("http://naukri.com");
        WebDriverWait wait =new WebDriverWait(driver,30);
        String homePage=driver.getWindowHandle();
        System.out.println("homePage");
        java.util.Set windows= driver.getWindowHandles();
        System.out.println(windows.size());
    
        for(String window:windows){
             String currentwindow=window;
                     if (!currentwindow.equals(homePage)){
                         driver.switchTo().window(currentwindow);
                         driver.close();
                         driver.switchTo().window(homePage);
                        
                     }  
//end if
                     }  //end for
}

***************************************************************************************
QACult Best Software Testing Courses in Chandigarh tricity.- We love to enhance your knowledge.
QACult is the premier institute catering to the requirements of experienced and fresh pass-out that gives leaders like you a new way to experience Quality engineering—while you work and giving you the flexibility to both advance your career.
Our faculty have 12+ years of industrial experience and have developed many automation testing frameworks in java using TestNG or BDD (cucumber) methodology. We expertise in developing automation testing frameworks in java, python, javascript, php, ruby(WATIR-webdriver & Capybara) and Appium.
please subscribe our channel for more such updates:  
And visit for website: www.qacult.com for various blogs and Upcoming Events.

Comments

Popular posts from this blog

Robot Framework With Python: An Open Source Framework For RPA

Robot Framework in python with RIDE

How to do copy Paste in browser using selenium using Actions class