Quick test professional

QTP Tips QTP codes QTP Faqs and more

Close Opened Browsers Except QC

Dim intIndex
Set oDesc=Description.Create
oDesc(“micclass”).Value=”Browser”
intIndex=0
While Browser(“micclass:=Browser”,”index:=”&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
else
intIndex=intIndex+1
End if
wend

March 17, 2011 Posted by | Browser Scripts, Descriptive programming, Descriptive Programming and Child Objetcs | 7 Comments

Get Each Radio in RadioGroup And Check

Get Each Radio in RadioGroup

And Check

Set opt=Description.Create
opt(“html tag”).value=”INPUT”
opt(“type”).value = “radio”
Dim allOptions,all
Set allOptions=Browser(“a”).Page(“b”).Frame(“c”).ChildObjects(opt)
all=allOptions.count
MsgBox all

for i= 0 to all
eName=allOptions(i).getROProperty(“name”)
noofradio=allOptions(i).getElementsByName(eName).length
for j= 0 to noofradio-1
radioname=allOptions(i).object.document.getElementsByName(eName).item(j).GetAdjucentText(“afterend”)allOptions(i).object.document.getElementsByName(eName).item(j).checked=true
msgbox radioname
next
next

  Source: Mercury Forum’s KB articles

February 14, 2008 Posted by | Descriptive Programming and Child Objetcs | , , , , , , , , | 8 Comments

Simple Code To Check All Links

‘***********************************************************************

‘SCENARIO NAME  :Check all links

‘DESCRIPTION    :This code Check all links  in any web page

‘PRECONDITIONS  :This Assume that when click on Link the new page will open on  current  window but not  in new  window

‘AUTHOR    :Mohan kumar kakarla

‘***********************************************************************

Set oDesc = Description.Create()

‘ Retrieve HTML tag <A>

oDesc(“html tag”).Value = “A”

Set rc = Browser(“title:=.*”).Page(“title:=.*”).ChildObjects(oDesc)

num = rc.Count()’get the number of  link in a page

For i=0 to num-1

               Set rc = Browser(“title:=.*”).Page(“title:=.*”).ChildObjects(oDesc)

        ref = rc(i).GetROProperty(“href”)’get the “href”propety of the i th link

        Browser(“title:=.*”).Page(“title:=.*”).link(“text:=.*”,”index:=”&i).click’click on i th link

        Browser(“title:=.*”).sync

        title1=Browser(“title:=.*”).getRoproperty(“title”)’get the tile of the target page

        MsgBox title1

        Browser(“title:=.*”).navigate(ref)’Navigates to the url  taken from “href” property

        Browser(“title:=.*”).sync

                title2=Browser(“title:=.*”).getRoproperty(“title”)’get the tile of the tNavigated page

                MsgBox title2

                           If title1=title2 Then’condition to check for the targetted page and Navigated page

              Reporter.ReportEvent 0, “Navigated To Correct Page”,””&title1’Reports if correct

            else

             Reporter.ReportEvent 1,””&title1,””&title2

            End If

        Browser(“title:=.*”).back’Navigates back to main page

        Browser(“title:=.*”).sync

Next

February 14, 2008 Posted by | Descriptive Programming and Child Objetcs | , , , , , , , , | 2 Comments

How to return the total number of links in a webpage and their names and URLs

How to return the total number of links in a webpage and their names and URLs

Solution: Use ChildObjects to get the link collection, then retrieve the properties

Use the ChildObjects method to retrieve all the links on the specified webpage. Once you have the collection, you can use the GetROProperty method to retrieve the innertext (name) and href (URL) values.

object.ChildObjects (pDescription)

object

A Page or Frame object.

pDescription

The description of the object to retrieve.

Use the Description object to store the description of the object type to retrieve.

Example:
‘ The sample was created against http://www.google.com
Set oDesc = Description.Create()
‘ Retrieve HTML tag <A>
oDesc(“html tag”).Value = “A”
Set rc = Browser(“Google”).Page(“Google”).ChildObjects(oDesc)
num = rc.Count()

For i=0 to num-1
   tag = rc(i).GetROProperty(“innertext”)
   href = rc(i).GetROProperty(“href”)
   Reporter.ReportEvent 0, “Links in Page”, “name: ” & tag & “;    url: ” & href
Next

    Source: Mercury Forum’s KB articles

 

February 14, 2008 Posted by | Descriptive Programming and Child Objetcs | , , , , , , , , | 3 Comments