Thursday, October 23, 2008

QuickTest Professional (QTP) Questions and Answers Part 2


  1. How to close all the Internet expolere windows and their dialog boxes
    SystemUtil.CloseProcessByName("IEXPLORE.exe")

  2. How to open the browser through script?
    a) To open Firefox
    SystemUtil.Run "firefox.exe", URL, , , SHOW_MAXIMIZED

    b) To open Internet Explorer
    SystemUtil.Run "iexplorer.exe", URL, , , SHOW_MAXIMIZED


  3. How to retrive the whole text of the page ?
    var = Browser("title:= title").page("title:=title").Object.documentElement.innertext

    OR

    var = Browser("title:= title").page("title:=title").WebElement("html tag:=BODY").getROProperty("innertext")


  4. How to add array and retrive the Dictionary Object ?
    Function DicDemo
    Dim a, d, i, s, arr(2) ' Create some variables.
    Set d = CreateObject("Scripting.Dictionary")
    arr(0)=0
    arr(1)=1
    arr(2)=2
    d.Add "Arr", arr
    a = d.Items ' Get the items.
    newarr=a(0)
    For i=0 to ubound(newarr)
    msgbox newarr(i)
    Next
    End Function

    Call DicDemo



  5. How to retrive the static text of the Dialog Box
    Dialog("text:=MyWindow").Static(nativeclass:=Static").GetROProperty("text")

    OR

    Dialog("text:=MyWindow").Static(nativeclass:=Static","Index:=0").GetROProperty("text")


  6. How to store the double quoted text in the variable ?
    strname= """Gaurang"""
    msgbox strname

    strname= chr(34)&"Gaurang"&chr(34)
    msgbox strname


  7. How to close all the opened browsers ?
    While Browser("CreationTime:=0").Exist
    Browser("CreationTime:=0").Close
    Wend

    Creation time is a special property associated with the Browser Object. The value of this property show the order in which the browser has opened. The First Browser that opens receives the Value 0. And so when you close the first Browser the value of this property in all the browser decrease by 1.