QTP中Description对象使用的一点经验

时间:2008-11-10 10:42:38  来源:51Testing  作者:  字号:【
我们在用QTP进行自动化脚本开发的时候,经常会要使用到Descrīption对象,但是在使用Descrīption时,却有一个问题,那就是在得到了所有子对象后,进行循环点击时,经常会循环几次后,就报generic error而使脚本不能再往下执行,开始的时候很不明白,为什么会出现这种情况,后来经过找资料和自己实践,终于搞清楚了原因,先看代码:

Set ōDesc=Descrīption.Create()
 oDesc("micclass").Value ="Link"
 Set Lists=Browser("Yahoo!奇摩").Page("Yahoo!奇摩").ChildObjects(oDesc)
 no = Lists.count - 1

For i = 0 To no 
 no = Lists.count - 1
 Print i & Lists(i).GetRoProperty("innertext") & ":" & Lists(i).GetROProperty("url")
  If  instr(1,Lists(i).GetROProperty("url"),"http") = 1 Then
  Lists(i).Click
Dialog("Connect to tw.yahoo.com").WinButton("Cancel").Click @@ hightlight id_;_395324_;_scrīpt infofile_;_ZIP::ssf21.xml_;_
Browser ("Yahoo!奇摩").Page("Yahoo!奇摩").Sync @@ hightlight id_;_Browser("Yahoo!奇摩").Page("Yahoo!奇摩")_;_scrīpt infofile_;_ZIP::ssf22.xml_;_
Browser("Yahoo!奇摩").Close
  If Lists(i).GetRoProperty("innertext") = "寬窄頁面切換" Then
   i = i -1
  End If
 else
  Services.LogMessage  Lists(i).GetRoProperty("innertext") & "没有URL" , ErrorMsg
  End If
 Browser("Yahoo!奇摩").Sync
  
 if  Browser("Yahoo!奇摩").Page("Yahoo!奇摩").WebElement("notopenthelink").Exist(3) Then
  Services.LogMessage  i & Lists(i).GetRoProperty("innertext") & "連結錯誤" , ErrorMsg
 'sheetNew.cells(j+1,1).value = Lists(i).GetROProperty(text)
 'sheetNew.cells(j+1,2).value = Lists(i).GetROProperty(url)
 End If
   Browser("Yahoo!奇摩").Navigate("http://tw.yahoo.com/index.html")
   Browser("Yahoo!奇摩").Sync

    这个循环在运行几次后就会报错,我们只要在for循环下面加上一句:

 Set Lists=Browser("Yahoo!奇摩").Page("Yahoo!奇摩").ChildObjects(oDesc)

这样就不会报错了,原因是因为Lists是一个数组,在第一次赋给页面子对象以后,运行几次就会丢失对象,这样在再继续循环就会报错,这也可以算是QTP本身的一个BUG,所以各位朋友在以后用这个对象时要注意这个地方,谢谢啦!

   如果还有不明白的可以加我 

   MSN:yidecai 

   or QQ:258020380

   我会第一时间回复的,谢谢大家的支持。

0

顶一下

0

埋一下

引用地址: