How to switch pop-up handler using selenium webdriver



  • I am working on a application that opens a form to fill up when i click on a button. I need to switch to that window , fill up the form and come out I tried this code

    Set beforePopup = driver.getWindowHandles();

    //code to click on add button to open the pop-up

    driver.findElement(By.xpath("//body[@id='ext-gen1018']/div[@id='contentPanel-1461']/div[@id='contentPanel-1461-body']/div[@id='campaigns-1464']/div[@id='campaigns-1464-body']/span[@id='campaigns-1464-outerCt']/div[@id='campaigns-1464-innerCt']/div[@id='campaignscoveragegrid-1494']/div[@id='toolbar-1507']/div[@id='toolbar-1507-innerCt']/div[@id='toolbar-1507-targetEl']/a[@id='button-1508']/span[@id='button-1508-btnWrap']/span[@id='button-1508-btnEl']/span[@id='button-1508-btnIconEl']")).click();

        Set  wndHandler = driver.getWindowHandles();
        Iterator  it = wndHandler.iterator();
        String Parent = it.next();
        String Child = it.next();
        driver.switchTo().window(Child);
    

    I am getting no such element exception



  • you can use following code to switch between windows based on the window title. or please go through this link Link

     private void handleMultipleWindows(String windowTitle) {
                Set windows = driver.getWindowHandles();
    
                for (String window : windows) {
                    driver.switchTo().window(window);
                    if (driver.getTitle().contains(windowTitle)) {
                        return;
                    }
                }
            }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2