1、input标签类元素文件上传
先定位到文件上传元素id,再使用方法send_keys(文件路径)
2、非input标签
备注:非input标签的文件上传,就不适用于此方法了,需要借助autoit工具或者SendKeys第三方库。
3、使用sendkeys库实现文件上传
首先安装库:pip install sendkeys
实现上传:首先定位到上传按钮并点击按钮弹出os框
其次SendKeys.SendKeys(file) #参数为上传文件路径
SendKeys.SendKeys('{ENTER}') #参数为ENTER表示键盘enter建