QTP code - Using Description Objects











Sponsored Links:


 Using Description Objects to interact with a web page.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
This example will illustrate how to use description objects to interact with a web page, www.QTPHelper.com to be more exact...

Note that for the Browser and Page I've used programmatic descriptions, but for the buttons, edits and check-boxes I've used Description Objects. Also take note of the regular expression in the Browser and Page description, just in case the titles change in the future.

You can add more properties to your description objects if you need to, i.e. if your web page has numerous objects of the same type with similar property values.


Dim objLogout
Dim objUser
Dim objPass
Dim objRemember

' create description objects for each item we are dealing with
Set objLogout   = Description.Create()
Set objUser     = Description.Create()
Set objPass     = Description.Create()
Set objRemember = Description.Create()

' define the properties of each item
objLogout("Name").Value   = "Logout"
objUser("Name").Value     = "username"
objPass("Name").Value     = "passwd"
objRemember("Name").Value = "remember"

' check that the user isn't already logged in
If Browser("Title:=QTP Helper.*").Page("Title:=QTP Helper.*").WebButton(objLogout).Exist(1Then

    ' click logout
    Browser("Title:=QTP Helper.*").Page("Title:=QTP Helper.*").WebButton(objLogout).Click 

End If

' set the user name
Browser("Title:=QTP Helper.*").Page("Title:=QTP Helper.*").WebEdit(objUser).Set "User"

' set the password
Browser("Title:=QTP Helper.*").Page("Title:=QTP Helper.*").WebEdit(objPass).Set "Password"

' tick the remember-me tickbox
Browser("Title:=QTP Helper.*").Page("Title:=QTP Helper.*").WebCheckBox(objRemember).Set "ON"



Source: https://qtphelper.com

0 comments: