標籤:ESS div dial NPU 上傳檔案 int style 多檔案上傳 img
selenium上傳檔案的方式
input類型上傳檔案:
1 #開啟上傳檔案頁面2 3 file_path = ‘file:///‘ + os.path.abspath(‘test3.html‘)4 5 driver.get(file_path)6 7 #定位上傳按鈕,添加本地檔案8 9 driver.find_element_by_name("file").send_keys(r‘F:\xxxx\meinfoSSZNZLYX.txt‘)
View Code
非input類型上傳檔案:
通過pip install pypiwin32安裝win32gui和win32con的庫
單檔案上傳:
1 import win32gui 2 3 import win32con 4 5 6 7 # win32gui 8 9 dialog = win32gui.FindWindow(‘#32770‘, u‘檔案上傳‘) # 對話方塊名字,不同流量器不同名10 11 ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, ‘ComboBoxEx32‘, None)12 13 ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, ‘ComboBox‘, None)14 15 Edit = win32gui.FindWindowEx(ComboBox, 0, ‘Edit‘, None) # 上面三句依次尋找對象,直到找到輸入框Edit對象的控制代碼16 17 button = win32gui.FindWindowEx(dialog, 0, ‘Button‘, None) # 確定按鈕Button18 19 20 21 win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, r‘C:\Users\AS\Desktop\inteData.xlsx‘) # 往輸入框輸入絕對位址22 23 win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button) # 按button
View Code
多檔案上傳:
1 dialog = win32gui.FindWindow(‘#32770‘, u‘檔案上傳‘) # 對話方塊2 ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, ‘ComboBoxEx32‘, None) 3 ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, ‘ComboBox‘, None)4 Edit = win32gui.FindWindowEx(ComboBox, 0, ‘Edit‘, None) 5 button = win32gui.FindWindowEx(dialog, 0, ‘Button‘, None) 6 7 win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, r‘"C:\Users\AS\Desktop\inteData.xlsx" "C:\Users\AS\Desktop\inteData.xlsx"‘) #多檔案上傳8 win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)
View Code
selenium 上傳檔案