账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    python+selenium win32gui实现文件上传,代码能运行但是没有实现效果
    39
    0
    upload = dr.find_element_by_id('exampleInputFile0')
    upload.click()
    time.sleep(1)
    
    # win32gui
    dialog = win32gui.FindWindow('#32770', u'文件上传')  # 对话框
    
    ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, 'ComboBoxEx32', None) 
    
    ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)
    
    Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)  # 上面三句依次寻找对象,直到找到输入框Edit对象的句柄
    
    button = win32gui.FindWindowEx(dialog, 0, 'Button', None)  # 确定按钮Button
    
    
    win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, 'D:\category.sql')  # 往输入框输入绝对地址
    
    win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)  # 按button
    
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 曾爱曾喜曾忧伤 普通会员 1楼

      要实现 Win32GUI 实现文件上传,您需要使用 Selenium 和 Python 的 PyAutoGUI 库。以下是一个基本的示例,说明如何使用这两个库来实现文件上传功能。

      首先,确保已安装了以下库:

      bash pip install selenium pip install pyautogui

      然后,您可以使用以下代码实现文件上传:

      ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from pyautogui import wait_for_keys from selenium.webdriver.common.by import By.ID

      def upload_file(): # 创建一个新的浏览器实例 browser = webdriver.Chrome()

      # 设置要上传的文件路径
      file_path = "/path/to/your/file"
      
      # 让浏览器找到文件并选择它
      browser.find_element_by_id("file_input").send_keys(file_path)
      
      # 等待文件上传完成
      WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "upload_button"))).click()
      
      # 关闭浏览器
      browser.quit()
      

      if name == "main": upload_file() ```

      在这个示例中,我们首先导入所需的库,然后定义一个 upload_file 函数,该函数用于打开一个新的浏览器实例,设置要上传的文件路径,然后让用户选择文件并点击上传按钮。最后,我们等待文件上传完成,并关闭浏览器。

      请注意,您需要将 "/path/to/your/file" 替换为实际的文件路径,以及 upload_button 为实际的上传按钮 ID。

      此外,如果您使用的是 PyAutoGUI,您可能需要使用 PyAutoGUI 的 WaitForKey 函数来等待用户按下上传按钮。您可以在 upload_file 函数中使用以下代码:

      ```python

      等待用户按下上传按钮

      wait_for_keys("Click the upload button") ```

      这个代码会等待用户按下 id="upload_button" 的按钮。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部