python如何IE另存為附件

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")

該方法通過鍵盤操作,自動另存為相關文件路徑

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。