QTP学习

来源:互联网 发布:数控车床g72编程实例 编辑:程序博客网 时间:2024/05/02 15:06

2009-10-18 20:52:14

DOM技术的应用

1.最普通的方法
  Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("wd").Set "helloworld" 

2.描述性编程
  Browser("百度一下,你就知道").Page("百度一下,你就知道").webedit("name:=wd").Set "123"

3.对象自身接口
  Browser("百度一下,你就知道").Page("百度一下,你就知道").WebEdit("wd").Object.value="helloworld"

4.DOM技术
  Browser("百度一下,你就知道").Page("百度一下,你就知道").Object.getElementById("kw").value="helloworld"

5.childobject结合描述性编程循环遍历获取对象
  '描述对象  
  Set Desc = Description.Create()  
  oDesc("micclass").Value = "WebEdit" 
  '获取webedit的数量  
  edit_count=Browser("百度一下,你就知道").Page("百度一下,你就知道").ChildObjects(oDesc).count  
 '获取子对象集合  
  set editobjects=Browser("百度一下,你就知道").Page("百度一下,你就知道").ChildObjects(oDesc)  
  For i=0 to edit_count-1  
    If editobjects(i).GetROProperty("name")="wd" then  
        editobjects(i).set "helloworld" 
    End If 
  Next 

6.getElementsByName和getElementsByTagName返回的都是一个集合对象
  getElementsByName:
  '*****************************
  Set pageOjbect=Browser("百度一下,你就知道").Page("百度一下,你就知道")
  set editObjs= pageOjbect.Object.getElementsByName("wd")
  For each obj in editObjs
    obj.value="helloworld"
  Next
  '*****************************

  getElementsByTagName:
  '*****************************
  Set pageOjbect=Browser("百度一下,你就知道").Page("百度一下,你就知道")
  set editObjs= pageOjbect.Object.getElementsByTagName("input")  
  For i=0 to editObjs.length
    If editObjs.item(i).name="wd" Then
      editObjs.item(i).value="helloworld"
      Exit for
    End If
  Next
  Set editObjs=nothing
  Set pageObject=nothing
  '*****************************

对象库

  DESCRIPTION PROPERTIES:用于对象识别时对比的属性
  ordinal indentifier :是针对出现相同对象时可以自动给对象进行编号,也就是INDEX
  Additional details:qtp的智能识别,意思就是如果打开了智能识别之后,QTP如果在页面上找不到对象之后,他会找最接近的一个对象进行匹配,,但是如果关闭了这个功能之后,只要有一个属性不匹配,QTP就会找不到对象的