如何在UFT/QTP中在运行时创建描述对象模型? [英] How to create description object model at runtime in uft/qtp?

查看:130
本文介绍了如何在UFT/QTP中在运行时创建描述对象模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

thank you for taking a look on this question. Just wondering if there is a best approach to create description object model at runtime. My code fails
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

I am making a call from action CreateDescObjAt_RunTime "Account Login","Your Store", "WebButton", "", "Account Login", "Login", "" And this is failing. However if I un comment this line & comment problem line, it works Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick

能否请您以正确的方式帮助我?谢谢

Could you please help me with the right approach? thanks

推荐答案

如果要设置通用浏览器和页面,则可以简单地使用与您已注释的行类似的语句:

If you want to set a generic browser and page you can simply use a statement similar to the line you have commented:

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

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

The line above will create a page object that you can work with.

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

Check the parameters being passed to your function to make sure you are correctly identifying your browser and page.

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

For the part of your actual object, which you want to create at runtime, you need to create a Description object, then look for the ChildObjects of your main object (in this case, your page) and store it to a collection. After that you can check whether or not your object is found. So your Select Case part would be something like this:

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

这篇关于如何在UFT/QTP中在运行时创建描述对象模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆