QTP using Native Properties

Category:
Question ID: 104132
3
0

I’m trying to use the Native Properties of an object on a website. I’ve used the Identification properties, but there are 6 different items on the site (only 2 are visible to the user) with the same ID properties. The only differences I’ve found so far are in the Native Properties. How do I use the Native Properties to set a variable? This is what I’ve done so far (all ID properties): Set Go=Description.Create() Go("micclass").Value="WebButton" Go("class").Value = "goButton" Go("type").Value = "submit" Set b=browser("title:=.*").Page("title:=.*").ChildObjects(Go) c=b.count msgbox c I tried using a Native Property that is definitely a characteristic native to this particular WebButton: Go("sourceIndex").Value = "453 but I’m not getting anything to return. I want to use the variable to descriptively program the click of a WebButton.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 9, 2010 3:22 pm
9 views
Answers (6)
5
Private answer

If the specific button in your case has a native property that doesn't change (like sourceIndex = 448), then you can use descriptive programming like this example to click the proper button.

Set Go=Description.Create()
Go(''micclass'').Value=''WebButton''
Go(''class'').Value = ''goButton''
Go(''type'').Value = ''submit''
Set buttonCollection=browser(''title:=.*'').Page(''title:=.*'').ChildObjects(Go)
c=buttonCollection.count
msgbox c

For i=0 to c-1
    set CurrentButton= buttonCollection(i).Object
    myindex = CurrentButton.sourceindex
    If StrComp(myindex,''448'')=0 Then
        CurrentButton.click
    End If
Next
Marked as spam
Posted by (Questions: 6, Answers: 167)
Answered on June 11, 2010 6:12 pm
So, the next line of my script to actually click the button would read: Browser(''title:=.*'').Page(''title:=.*'').WebButton(CurrentButton).Click
( at June 14, 2010 5:52 pm)
2
Private answer

You can use the attribute/ notation to access native properties of Web objects.

You can then either use these properties to identify such objects with programmatic descriptions, or modify the Object recognition of your QTP client to store some of these custom attributes for newly learned objects. in your case, it will be the former.

For example, suppose a Web page has the same company logo image in two places on the page: You could identify the image that you want to click using a programmatic description by including the user-defined property LogoID in the description as follows:

Browser(''Mercury Tours'').Page(''Find Flights'').Image ''src:=logo.gif'',''attribute/LogoID:=123?).Click 68, 12 
Marked as spam
Posted by (Questions: 6, Answers: 167)
Answered on June 9, 2010 6:24 pm
Can I use the sourceIndex?
( at June 9, 2010 7:02 pm)
1
Private answer

Here's what I'm thinking: Browser("title:=.").Page("title:=.").WebButton("className:=goButton", "attribute/sourceIndex:=453").Click Is that possible?

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on June 9, 2010 7:10 pm
0
Private answer

I have a login button which does not get enabled while running the qtp script. How to make it nongrayed and click descriptively? Set editDesc = Description.Create() Set btnDesc = Description.Create() editDesc("micclass").Value = "WebEdit" btnDesc("micclass").Value = "WebButton" btnDesc("name").Value ="Log in" Set edits = Browser("title:=SJDMS").Page("title:=SJDMS").ChildObjects(editDesc) Set btn = Browser("title:=SJDMS").Page("title:=SJDMS").ChildObjects(btnDesc) 'MsgBox edits.Count 'MsgBox btn.Count edits(0).Set Environment("Login") edits(1).SetSecure Environment("Password") Set WshShell = CreateObject("WScript.Shell") Wait(5) WshShell.SendKeys "{ENTER}" Set WshShell = Nothing 'btn(0).Click() .. this does not work since the login button is grayed out and "enter" one is also not working.

Marked as spam
Posted by (Questions: 0, Answers: 1)
Answered on January 21, 2011 4:36 pm
0
Private answer

So, the next line of my script to actually click the button would read:
Browser(''title:=.'').Page(''title:=.'').WebButton(CurrentButton).Click

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on June 14, 2010 5:56 pm
0
Private answer

I finally got it to work, but the Source Index had to be replaced with a different Native Property. Source Index just changes too much.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on June 17, 2010 8:28 pm