代码语言:javascript复制
# pywinauto selenium 实现文件上传
import pywinauto
from selenium impor webdriver
from pywinauto.keyboard import send_keys
# 测试网址
url = "https://www.layui.com/demo/upload.html"
browser = webdriver.Chrome()
browser.get(url=url)
# 点击上传按钮
browser.find_element_by_xpath("//button[@id=test2]").click()
def upload_files(file_path, file, *args):
app = winauto.Deskpytop() # 获取桌面所有数据
dlg = app["打开"]
dlg.print_control_identifiers()
dlg["Toolbar3"].click()
send_keys(file_path)
send_keys("{VK_RETURN}")
dlg["文件名(&N):Edit"].type_keys('"{}"'.format(file))
for i in args:
send_keys('"{}"'.format(i))
dlg["打开(&o)"].click()
upload_files("C:images", "a.png", "b.png", "c.png")