uft/qtp 如何在运行时创建描述对象模型?

How to create description object model at runtime in uft/qtp?

感谢您查看此问题。只是想知道是否有在运行时创建描述对象模型的最佳方法。我的代码失败
Object doesn't support this property or method: 'Browser(...).page(...).WebButton'

FunctionCreateDescObjAt_RunTime(StrBrowserNme,StrBrwsrTitle,StrObject,StrPgeNme,StrPgtitle,StrObjectName,index)`

    'create a description object for Browser & Page`

    Set WebBrwsrDesc= Description.Create
        WebBrwsrDesc("application version").value= "Internet Explorer.*"
        If StrBrowser<>"" Then
            WebBrwsrDesc("name").value=StrBrowserNme
            WebBrwsrDesc("title").value=StrBrwsrTitle
        End If

    Set WebPageDesc= Description.Create
        WebPageDesc("name").value=StrPgeNme
        WebPageDesc("title").value=StrPgtitle

'   'Based on the type of object, execute the condition`

    Select Case StrObject`

        Case "WebButton"
            Set WebBtnDes= Description.Create
            WebBtnDes("html tag").value="INPUT"
            WebBtnDes("name").value=StrObjectName   
            WebBtnDes("micclass").value="button"
            WebBtnDes("index").value=index
            'Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
            Browser(WebBrwsrDesc).page(WebPageDesc).WebButton(WebBtnDes).click

    end select

End Function

我正在行动呼吁 CreateDescObjAt_RunTime "Account Login","Your Store", "WebButton", "", "Account Login", "Login", "" 这是失败的。但是,如果我取消评论此行并评论问题行,它会起作用 Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick

你能帮我找到正确的方法吗?谢谢

如果你想设置一个通用的浏览器和页面,你可以简单地使用类似于你评论的行的语句:

Dim objPage : Set objPage = Browser("class:=browser").Page("title:=.*")

上面的行将创建一个您可以使用的页面对象。

检查传递给您的函数的参数,确保您正确识别浏览器和页面。

对于要在运行时创建的实际对象部分,您需要创建一个 Description 对象,然后查找主对象的 ChildObjects(在本例中,您的页面)并将其存储到集合中。之后,您可以检查是否找到了您的对象。所以你的 Select Case 部分应该是这样的:

Select Case StrObject

    Case "WebButton"
        ' This is just a description of your object, not your actual object
        Dim descButton : Set descButton = Description.Create
            descButton("html tag").value="INPUT"
            descButton("name").value=StrObjectName   
            descButton("micclass").value="button"
            descButton("index").value=index

        ' In the following statement you are looking for all child objects
        ' of your page that matches with your description, and storing it
        ' into the collButton collection
        Dim collButton : Set collButton = Browser("class:=browser").Page("title:=.*").ChildObjects(descButton)

        If collButton.count > 0 Then ' Now you are checking if any object was found
            ' There are many ways to get the button object that you want.
            ' Here I'm just assuming you want the first one, but you could iterate
            ' into the collection to make sure you have the right one
            Dim objButton : Set objButton = collButton(0) ' I'm getting the first item, which is in index 0 of your collection
            objButton(0).Click ' This object already have the whole Browser().Page().WebButton() identified, so no need to use it
        Else
            MsgBox "No WebButton found. Please check your Description object"
        End If

    ' Your other cases...

    End Select

Webbutton 的 MicClass 不能是按钮。应该是 WebButton

'您正在使用以下内容

WebBtnDes("micclass").value="button"

应该是:WebButton

'无论如何描述描述对象

Set ObjButton=Description.Create
ObjButton("MiCClass").value="WebButton"
ObjButton("name").value=strButtonName
ObjButton("htmlid").value=strHtmlId
Set ObjButton= Browser().page().ChildObject(ObjButton)