|
其实不用那么麻烦的找关联关系,不用钻牛角尖,想一个通用直观有效的方法,就是根据坐标来定位某个对象相应的WebCheckbox
吐血大奉献,写了一个通用函数,可以一劳永逸的解决类似问题,适合各种情况- '================================================================
- ' FUNCTION NAME:
- ' FindCheckBox
- ' FUNCTION DESCRIPTION:
- ' Find the corresponding webcheckbox of title object in parent object, and output the webcheck
- ' FUNCTION USAGE:
- ' Set parentObject = Browser("ATS Login").Page("ATS Login").Frame("mainRight")
- ' Set titleObject = Browser("ATS Login").Page("ATS Login").Frame("mainRight").Link("test")
- ' ret = FindCheckBox(parentObject, titleObject, checkBoxObject)
- ' checkBoxObject.Set "ON"
- ' FUNCTION PARAMETER
- ' ParentObject: The parent object of title object and webcheckbox object
- ' TitleObject: The title object
- ' CheckBoxObject: [Output Param] Output the corresponding webcheckbox object of title object
- ' FUNCTION RETURN:
- ' 0: Success to find and output the corresponding webcheckbox object of title object
- ' -1: Fail to find the corresponding webcheckbox object of title object
- ' FUNCTION ORIGINAL CREATOR:
- ' yabest
- ' FUNCTION CREATION DATE:
- ' 2007-08-30
- ' FUNCTION UPDATE HISTORY:
- '===============================================================
- Function FindCheckBox(ByVal ParentObject, ByVal TitleObject, ByRef CheckBoxObject)
- Dim titleObjectY1, titleObjectY2, curChildObjectMidY
- Dim checkBoxDesc, childObjects
- Dim childNum, childIndex, findIndex
- 'Get the title object's top/bottom y position
- titleObjectY1 = CInt(TitleObject.GetROProperty("abs_y"))
- titleObjectY2 = CInt(TitleObject.GetROProperty("abs_y")) + CInt(TitleObject.GetROProperty("height"))
- 'get all webcheckbox objects
- Set checkBoxDesc = Description.Create()
- checkBoxDesc("micclass").Value = "WebCheckBox"
- Set childObjects = ParentObject.ChildObjects(checkBoxDesc)
- 'search the webcheckbox according y position.
- childNum = childObjects.Count
- findIndex = -1
- For childIndex = 0 to childNum-1
- Set curChildObject = childObjects(childIndex)
- curChildObjectMidY = CInt(curChildObject.GetROProperty("abs_y")) + CInt(curChildObject.GetROProperty("height"))/2
- 'the webcheckbox should be: (y+height/2) in [titleObjectY1, titleObjectY2] area
- If curChildObjectMidY>=titleObjectY1 and curChildObjectMidY<= titleObjectY2 Then
- findIndex = childIndex
- Exit For
- End If
- Next
- 'if not found, return fail
- If findIndex = -1 Then
- FindCheckBox = -1
- Exit Function
- End If
- 'if found, return success
- Set CheckBoxObject = curChildObject
- FindCheckBox = 0
-
- End Function
复制代码
[ 本帖最后由 yabest 于 2007-8-31 15:35 编辑 ] |
|