Python 操作IE的弹出窗口

上传人:我*** 文档编号:135970182 上传时间:2020-06-21 格式:DOC 页数:6 大小:30.50KB
返回 下载 相关 举报
Python 操作IE的弹出窗口_第1页
第1页 / 共6页
Python 操作IE的弹出窗口_第2页
第2页 / 共6页
Python 操作IE的弹出窗口_第3页
第3页 / 共6页
Python 操作IE的弹出窗口_第4页
第4页 / 共6页
Python 操作IE的弹出窗口_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《Python 操作IE的弹出窗口》由会员分享,可在线阅读,更多相关《Python 操作IE的弹出窗口(6页珍藏版)》请在金锄头文库上搜索。

1、Python 操作IE的弹出窗口最近和朋友在群里讨论Selenium中,源码中Pyhon关闭IE的弹出窗口失效,后来小编给了个建议是先把焦点设置给一个隐藏的层,然后发送回车的方法去实现它。感觉颇为无奈,同时也发现在PAM30中也是没有实现处理弹出窗口的问题,为此今天在PAM30的基础上新增了下面几个方法:getmsgbox、getmsgboxtext、getmsgboxtitle、closemsgbox、clickmsgboxbutton等等。主要关键点在于getmsgbox方法的实现。def getmsgbox(self, filter = None): Get the specifiedP

2、opupmessage box parameters: filter - Only return elements that match this filter in format (title=Microsoft Internet Explorer;text=Are you sure to close the window;index:=0) The filter value to match. Regular Expressions can be used by starting the val with an ! title=!Google;text=!baidu #(Add by lu

3、chenzhi March 30,2010) returns: a popup message box hwnd MsgboxHwnd = 0 MatchTime = 0 MatchIndex = 0 try: for i in range(0,100) : MsgboxHwnd=win32gui.FindWindowEx(0,MsgboxHwnd,#32770,None) if MsgboxHwnd = 0 : break if win32gui.GetParent(MsgboxHwnd) = self._ie.Hwnd: if filter: valText = None filters

4、= filter.split(;) match = False for f in filters: atts = f.split(=) if atts0.lower() = title: valText = win32gui.GetWindowText(MsgboxHwnd) if atts0.lower() = text: FirstStaticHwnd = win32gui.FindWindowEx(MsgboxHwnd,0,Static,None) if win32gui.GetWindowText(FirstStaticHwnd): valText = win32gui.GetWind

5、owText(FirstStaticHwnd) else: valText = win32gui.GetWindowText(win32gui.FindWindowEx(MsgboxHwnd,FirstStaticHwnd,Static,None) if atts0.lower() = index : MatchIndex=int(atts1) if valText = None : match = True continue if valText != None: valText = str(valText) valText = valText.strip() valText = valTe

6、xt.lower() wantText = atts1.lower() if wantText0 = !: val = wantText.replace( !, , 1) myRE = pile(val) m = myRE.match(valText) if m: match=True else: match=False break elif valText = wantText : match = True else: match = False break else: return MsgboxHwnd if match: MatchTime = MatchTime+1 if MatchT

7、ime = MatchIndex+1: return MsgboxHwnd except: (ErrorType,ErrorValue,ErrorTB)=sys.exc_info() print (sys.exc_info() traceback.print_exc(ErrorTB) return None return None剩下的几个方法包括了:def clickmsgboxbutton(self, filter = None, buttonname = None): click the specifiedPopupmessage boxs button parameters: filt

8、er - Only return elements that match this filter in format (title=Microsoft Internet Explorer;text=Are you sure to close the window;index:=0) The filter value to match. Regular Expressions can be used by starting the val with an ! title=!Google;text=!baidu buttonname - the button name or index, it c

9、an use the Regular Expressions also. eg : Yes,!Ye,2 #(Add by luchenzhi March 31,2010) returns:True or false or None Mesgboxhwnd = self.getmsgbox(filter) if Mesgboxhwnd = None : return None else: ButtonHwnd=0 if type(buttonname) = type(1) : buttonindex=buttonname for t in range(0,buttonindex+1): ButtonHwnd=win32gui.FindWindowEx(Mesgboxhwnd

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 事务文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号