python在使用selenium下載附件時(shí),chrome,filefox都能自定義下載文件夾路徑,而IE不行。
這樣在自動(dòng)化時(shí),會(huì)相當(dāng)麻煩,網(wǎng)上介紹了很多方法,都比較麻煩。
個(gè)人解決辦法如下:
# 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")
該方法通過(guò)鍵盤(pán)操作,自動(dòng)另存為相關(guān)文件路徑