Chrome 上传文件自动化

时间:2024-11-06 07:29:05
#这里使用chromedriver71 版本,稳定可使用 driver = webdriver.Chrome(executable_path=r"F:\chromedriver\") url = "打开的网页" #内部是发送http请求 driver.get(url) driver.implicitly_wait(20) #定位发送的文件元素 elem = driver.find_element_by_name('该元素文上传的按钮元素') time.sleep(2) elem.click() time.sleep(2) # elem.send_keys(r'E:\') import win32gui import win32con dialog = win32gui.FindWindow("#32770","打开")#一级窗口 ComboBoxEx32 = win32gui.FindWindowEx(dialog,0,"ComboBoxEx32",None)#二级 comboBox = win32gui.FindWindowEx(ComboBoxEx32,0,"ComboBox",None)#三级 edit = win32gui.FindWindowEx(comboBox,0,"Edit",None)#四级 button = win32gui.FindWindowEx(dialog,0,"Button",None)#四级 #操作 WM_SETTEXT设置文本内容 time.sleep(2) win32gui.SendMessage(edit,win32con.WM_SETTEXT,None,"发送文件路径")#发送文件路径 time.sleep(2) win32gui.SendMessage(dialog,win32con.WM_COMMAND,1,button)#点击打开按钮