input类型:网上很多,暂不赘述
非input类型:使用PyUserInput库
2.1 安装
pip install PyUserInput
pip install PyWin32
2.2 使用
from pykeyboard import PyKeyboard
def send_pictures_windows(self, loc, file):
"""
上传图片
:param loc: 上传图片占位图元素的xpath
:param file: 图片在电脑本地的绝对路径
:return:
"""
self.click(loc) # 点击上传图片占位,打开系统窗口(此处是我封装了webdriver的click方法)
time.sleep(5)
k = PyKeyboard() # 实例化键盘操作对象
k.type_string(file) # 输入图片绝对路径
time.sleep(2)
k.tap_key(k.enter_key) # 敲击回车
k.tap_key(k.enter_key) # 敲击回车
time.sleep(3)