墨小洲

Lifelong nothing but love and freedom.

导航

Python+selenium+autoIT组合 处理swfupload上传图片

Posted on 2016-07-28 15:25  墨小洲  阅读(535)  评论(0)    收藏  举报

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即可

参考源码