How to close child browser window in Selenium WebDriver using Java

后端 未结 7 1621
傲寒
傲寒 2020-12-14 16:07

After I switch to a new window and complete the task, I want to close that new window and switch to the old window,

so here i written like code:

// P         


        
相关标签:
7条回答
  • 2020-12-14 17:09

    I've also tried

    1)driver.close();
    2)driver.quit();

    apparently, these methods don't work as expected!(not saying it don't work though) I've even tried making the driver class singleton and it didn't help me with running test cases parallel.so it was also not the optimal solution.finally, i came up creating a separate class to run a bat file.which the bat file contains commands of grouping all the chrome driver process and all the child processes of it.and from the java class I've executed it using Runtime.

    The class file that runs the bat file

    public class KillChromeDrivers {
    
        public static void main(String args[]) {
    
    
            try {
    
                Runtime.getRuntime().exec("cmd /c start E:\\Work_Folder\\SelTools\\KillDrivers.bat");
                //Runtime.getRuntime().exec()
            } catch (Exception ex) {
    
    
    
            }
        }
    
    }
    

    The command that you have to put in the [ .bat ] file

    taskkill /IM "chromedriver.exe" /T /F
    
    0 讨论(0)
提交回复
热议问题