QTP 最大化浏览器窗口

最近项目上要求将浏览器窗口最大化,并且要支持IE,Chrome,FireFox 3种浏览器

其实QTP有自带的

Browser("Web Testing").FullScreen。

但是看不到浏览器的title 不是很好,也不是我们想要的效果。

看了下网上的,之前都是这么处理的:

hwnd=Browser("Browser").GetROProperty("hwnd")

Window("hwnd:="&hwnd).Maximize
在IE6之后,就不好用了。
原因是将浏览器作为Browser对象取出来的hwnd(句柄),跟作为window对象取出来的根本就不一样。 Window("hwnd:="&hwnd)  qtp识别不到这个对象。

说了那么多,贴代码:

直接把桌面上micClass属性为window的对象(包括浏览器)全取出来,
在判断regexpwndtitle 的属性为ie,ff,chorme

Private sub MaximizeBrowser 
Dim oDesc:Set oDesc=Description.Create() 
oDesc("micClass").Value ="Window" 
dim olists:Set olists = Desktop.ChildObjects(oDesc) 
On error resume next :err.clear 
For i = 0 To olists.Count() - 1 
   Dim title:title=olists(i).getroproperty("regexpwndtitle") 
   If instr(title,"Internet Explorer") or instr(title,”Chrome&quot") or 
       instr(title,"Firefox") Then 
       olists(i).Maximize 
    End if 
Next 
On error goto 0 
Set olists=nothing 
Set oDesc=nothing 
End sub

 

猜你喜欢

转载自sunsgsg-eye.iteye.com/blog/2195843
QTP