python在使用selenium下载附件时,chrome,filefox都能自定义下载文件夹路径,而IE不行。 这样在自动化时,会相当麻烦,网上介绍了很多方法,都比较麻烦。 个人解决办法如下:
# IE另存为路径
def saveIeFile(self, filePath):
win32api.keybd_event(117, 0, 0, 0) # F6
win32api.keybd_event(117, 0, win32con.KEYEVENTF_KEYUP, 0) # F6
time.sleep(0.5)
win32api.keybd_event(9, 0, 0, 0) # TAB
win32api.keybd_event(9, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
time.sleep(0.5)
win32api.keybd_event(40, 0, 0, 0) # DOWN
win32api.keybd_event(40, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键
time.sleep(0.5)
win32api.keybd_event(65, 0, 0, 0) # A
win32api.keybd_event(65, 0, win32con.KEYEVENTF_KEYUP, 0) # A
time.sleep(0.5)
autoit.control_set_text("另存为", "Edit1", filePath)
time.sleep(1)
autoit.control_click("另存为", "Button2")
该方法通过键盘操作,自动另存为相关文件路径
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有