How to handle Windows file browse window using selenium webdriver

前端 未结 3 1982
失恋的感觉
失恋的感觉 2020-12-11 22:32

How to handle file window popup using selenium webdriver.

I have clicked on file browse button , new pop up window has been opened and i am unabled to handle this wi

3条回答
  •  北海茫月
    2020-12-11 22:46

    Use this Method for file handling:

    We need :

    jacob.jar Download

    It will contain one jar file and 2 .dll files

    AutoItX4Java.jar Download

    public static void uploadFile(String path, String browser){
    
        if(browser.equalsIgnoreCase("chrome")){
    
            if(x.winWaitActive("Open", "", 10)){
                if(x.winExists("Open")){
                    x.sleep(500);
                    x.send(path);
                    x.controlClick("Open", "", "Button2");
    
                }
            }
    
        }
    
    
        if(browser.equalsIgnoreCase("firefox")){
    
            if(x.winWaitActive("File Upload", "", 10)){
                if(x.winExists("File Upload")){
                    x.sleep(500);
                    x.send(path);
                    x.controlClick("File Upload", "", "Button2");
    
                }
            }
        }
    
        if(browser.equalsIgnoreCase("InternetExplorer")){
    
            if(x.winWaitActive("Choose File to Upload", "", 10)){
                if(x.winExists("Choose File to Upload")){
                    x.sleep(500);
                    x.send(path);
                    x.controlClick("Choose File to Upload", "", "Button2");
    
                }
            }
        }
    
    
    
    }
    
    
       public void test(){
           //Click on the Select button of the file upload
           uploadFile("Path", "chrome");
    
    
       }
    

    Thanks... Dont click Accept or Upvote until it works for you. If it is not working for you means, please comment.. Dont Downvote...

提交回复
热议问题