zoukankan      html  css  js  c++  java
  • selenium webdriver java处理上传

    public void uploadFile(String path) {
    
            //File file = new File("C:\jacob-1.18-M2-x64.dll");
    
            // System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());//把DLL加入到系统变量.或者丢到System32下
    
            AutoItX x = new AutoItX();
    
            Locale locale = Locale.getDefault();
    
            String title = "Open";
    
            String browserType = TestCase.DriverManager.browserType;
    
            if (browserType.equals("CHROME")) {
    
                if (locale.getDisplayLanguage().equals("中文")) title = "打开";
    
                if (x.winWaitActive(title, "", 10)) {
    
                    if (x.winExists(title)) {
    
                        x.sleep(500);
    
                        //x.send(path);
    
                        x.controlCommandEditPaste(title, "", "Edit1", path);
    
                        x.controlClick(title, "", "Button1");
    
                    }
    
                }
    
            }
    
            if (browserType.equals("FIREFOX")) {
    
                title = "File Upload";
    
                if (locale.getDisplayLanguage().equals("中文")) title = "文件上传";
    
                if (x.winWaitActive(title, "", 10)) {
    
                    if (x.winExists(title)) {
    
                        x.sleep(500);
    
                        //x.send(path);
    
                        x.controlCommandEditPaste(title, "", "Edit1", path);
    
                        x.controlClick(title, "", "Button1");
    
                    }
    
                }
    
            }
    
            if (browserType.equals("IE")) {
    
                title = "Choose File to Upload";
    
                if (locale.getDisplayLanguage().equals("中文")) title = "选择要加载的文件";
    
                if (x.winWaitActive(title, "", 10)) {
    
                    if (x.winExists(title)) {
    
                        x.sleep(500);
    
                        //x.send(path);
    
                        x.controlCommandEditPaste(title, "", "Edit1", path);
    
                        x.controlClick(title, "", "Button1");
    
                    }
    
                }
    
            }
    
        }
    
     
  • 相关阅读:
    拖拽模块move2
    拖拽模块move1
    String类和StringBuilder
    你真的会二分查找吗
    C++中关于new及动态内存分配的思考
    【转】Github 上传代码
    HDU4801·二阶魔方
    POJ2676,HDU4069解决数独的两种实现:DFS、DLX
    读书笔记
    SpringBoot-------实现多数据源Demo
  • 原文地址:https://www.cnblogs.com/zhangminjie/p/3959756.html
Copyright © 2011-2022 走看看