Python+selenium不能直接处理swfupload图片上传的问题。需要借助鼠标模拟点击按钮,调用autoit生成的exe处理程序完成。
1,selenium 元素定位到上传按钮,模拟鼠标点击
upload_20=self.brow.find_element_by_css_selector("#SWFUpload_20")
ActionChains(self.brow).click(upload_20).perform()
2,安装 autoit ,编写生成打开点击上传图片后的操作的exe程序
;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("打开", "","Edit1")
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set the File name text on the Edit field
ControlSetText("打开", "", "Edit1", "C:\upload_img.jpg")
Sleep(1000)
; Click on the Open button
ControlClick("打开", "","Button1");
3,最后调用autoit 生成的exe即可
参考源码
时间: 2024-12-11 13:00:33