zoukankan      html  css  js  c++  java
  • 上传控件

    '''
    selenium无法直接操作windows窗体,上传控件有属性(type="file")时,可直接sendkeys处理上传文件
    WebElement adFileUpload = driver.findElement(By.id(" ###"));
                        // 定位上传控件 
    String filePath = "C:\test\uploadfile \test.jpg";
                        // 定义了一个本地文件的路径 
    adFileUpload.sendKeys(filePath);
                        // 为上传控件进行赋值,将需要上传的文件路径赋给控件
    '''
    
    def upload_picture(by,locator,value):
        try:
            element = get_element(driver, by, locator)
            path = r"D:installsimages\%s.png"%(value)
            element.send_keys(path)
        except Exception as e:
            print(e)
    
    #实现非input标签上传文件,调用此方法需要打开windows上传文件的系统窗口再调用
    def upload_file(path):
        try:
            #file_path:上传文件的路径
            dialog = win32gui.FindWindow("#32770", "打开")
            comboxex32 = win32gui.FindWindowEx(dialog, 0, "ComboBoxEx32", None)
            combox = win32gui.FindWindowEx(comboxex32, 0, "ComboBox", None)
            edit = win32gui.FindWindowEx(combox, 0, "Edit", None)
            button = win32gui.FindWindowEx(dialog, 0, "Button", "打开(&0)")
            win32gui.SendMessage(edit, win32con.WM_SETTEXT, None, path)
            win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)
        except Exception as e:
            print(e)
  • 相关阅读:
    (转载)MP3 编码解码 附完整c代码
    (转载) 一个大概的框架
    (转载)音视频相关的书籍,多媒体技术
    js原生选项卡切换
    点击div删除div本身
    鼠标移入旋转动画
    鼠标移入,改变border颜色
    小白初建博客!
    java设计模式--六大原则
    java设计模式--策略模式
  • 原文地址:https://www.cnblogs.com/xiaochuichui/p/13280884.html
Copyright © 2011-2022 走看看