How to handle the new window in Selenium WebDriver using Java?

后端 未结 6 2134
北海茫月
北海茫月 2020-11-27 18:59

This is my code:

driver.findElement(By.id(\"ImageButton5\")).click();
//Thread.sleep(3000);
String winHandleBefore = driver.getWindowHandle();
driver.switchT         


        
6条回答
  •  眼角桃花
    2020-11-27 19:23

    Set windows = driver.getWindowHandles();
    Iterator itr = windows.iterator();
    
    //patName will provide you parent window
    String patName = itr.next();
    
    //chldName will provide you child window
    String chldName = itr.next();
    
    //Switch to child window
    driver.switchto().window(chldName);
    
    //Do normal selenium code for performing action in child window
    
    //To come back to parent window
    driver.switchto().window(patName);
    

提交回复
热议问题