You are on page 1of 13

c

WORKING WITH QTP


c
c  c c

Sunday, May 3, 2009


FIND CELL Value in EXCEL VB

Some Time we have to Check that particular Cell Value Exist or Not and required the Cell
addressc
rem this function return the first find Cell address value of your Excel sheet & Change
Color of Cell find value
rem input parameter xlFilePath := xls file path || FindValue =value which need to be findc
dim  ccFindValue 


c
 c !"#$ c
!c
%
c$ c%
c c
FindValue c
!c
&ccc
c
$ ccc



ccFindCellAddress'  cFindValue (c
! )$c


c

Public function FindCellAddress(Byval xlFilePath ,byval FindValue )c

Set ObjAppExcel = CreateObject(´Excel.Application´)


rem Disable alerts
ObjAppExcel.DisplayAlerts = False
r`  

` `
ObjAppExcel.Workbooks.open(xlFilePath)
REm Get the object of the first sheet in the workbook
Set objectSheet = ObjAppExcel.Sheets(´Sheet1Ǝ)

!c
%
c
c
c%!c*cc c!c
cc%c
c
cc

set objValueFind = objectSheet.UsedRange.Find(FindValue)


If not objValueFind is nothing Then
CellAddress =objValueFind.address
FindCellAddress=replace(objValueFind.address,´$´,´")
FindCellAddress=replace( FindCellAddress,´1Ǝ,´")c

Doc

set objValueFind = objectSheet.UsedRange.FindNext(objValueFind )c

Loop While Not objValueFind Is Nothing And objValueFind.Address <> CellAddressc

Exit functionc
End If
rem if not found then return the Empty
FindCellAddress=´NOT FOUND´c

Set objValueFind =nothing


Set objectSheet =nothing
Set ObjAppExcel =nothing
End Functioncc
 
c)+c !"cc,-.c/c0c!!
 c c
)
 c122133c11c 4"2c1c561c3711 c6312"81cc

Get EXCEL COLUMN VB / in Array

 c 13 /#$ c


!++cc8
!'  (c

Public functioncGetALLColumn'9+c$ 
 c(c

!c
%
c+c!c
2!c!'(c
3
c:)1$
cc

:)
'1$
#(c

!c2 )
c
 c
:)1$
#2 +
 cc 
c

!ccc &)&cc
c1$
cc
:)1$
#;&)& #
'$ 
 (c
<8
c
c)
c%c
c% c

cc
c &)&c
3
c)
3

cc:)1$
#3

 '3

*=(c

!cc
c!cc

c
!c)
3

#6

#! #c


2!c


c!'!>*(c
c0cc!>*c
!'(c)
3

#
 '*?*(#
c

"
$c

8
!c!c
3
c)
3

c c
3
c:)1$
c c
End Functionc

 
c)+c !"cc,-@c/c0c!!
 c c
)
 cA#c!c11c59c11cc

Select Radio Button QTP



!BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBc

c
Rem This function select the radio button with specified number of index
REM Input objRadiobutton:= radiobutton object intenetexplorer exe || nIndex:= number
of specifed radio button which need to be rem select
REM Output(ReturnType) := None
REM Created: 07/April/2009 Rajiv Kumar Nandvani ## REM Changed:MM/DD/YYYYc

1/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBc


c))c9
'9
(#
'
(##;
)'C8(c

4
$c*c
!c% cc)c

c

cfn_RadioButtonSelect())4
$(c

)cFunction fn_RadioButtonSelect'c)+
%c)))+c4
$(c

4
! c))#8
:
+'c
! (c
4
!  ' 4
! D(c
4
$c4
$>*c

4%c4
$cEc')' 4
! (c(c
c
))#

c 4
! '4
$(c


c
cF

c
&c!)
c%cc)c

1c4%c


!c
cc
c
%

cc
c:)
 c
3
c))c c
1c c

 
c)+c !"cc,,Gc/c0c!!
 c c
)
 c8
:
+c cc)cc

Work With text box( Windows WinEdit box) QTP

4c! c
c)
>&ccccc%
c c
c
%
)
c!
 c%c

Dc
%
!
cc c +c

+c
  cc 
c!
c&cc
c)
#c2)
cH&c


 c
cc%c
ccc c%
c c ccc)
c

c  c
c
c#cc 
>c&c

c!+c+c
c
c cc
cccc

c
c%c
c
$ ccc
!+c
c
c
c!
c#c"c#c
c
$ cc cc

c  c
c
c

#c4c !
c c

c!
c  cc
c

c)+c 
cc
ccc

c
c)$#c;
c 
c%c
c

c)
>&c!+cc
cc%c
c
$c


cc

+c%c

!
#c4c  c
c
c!
 c c  
+c
 
c cc%c
cc c



c c  c
cccc&
+)cc  c c))c c cc!
c
&#c:
c
c c c
cc
cc
c

c&
+ &
c

c?c7!
c
c?c3 %c?c1c
2


c

&
c
2'(#;1'
c"!
(# +
c!2 c?c!7!
c?c!6c
2'(#;1'
c"!
(# +
c!2 c?c!3 %2 c?c!1c?c
!3 %6c?c!6c

 
c)+c !"cc,,Ic/c0c!!
 c c

Work With List Box QTP

;
c
c
c c)$c:)
cc #c c
%!c% c
cc )$c#c&
cc

9
'9
(#
'
(##;
) ' 9$(#3

cF 9$5
c

4c

c
c
c%!c c9$c c
c! c)
c

cc c)$c
 
c c
cc

c&
c c

Fc
%+c
c 
%
c
!c%c
c 9$c)
#c%!c c
c 
%
c
!c c

cc
c)
J c
!c
#c

3c)
%
c

c+c
cc c)$c + c 
c
c
c+c
ccc

cc c
)$c! c)
c

c)+c
c  c!
 K c

!c) 9$c 5


! c) 
c

c) 9$cc9
'9
(#
'
(##;
) ' 9$(c
5
! c +
c5
c c

cc)
c
&c
) 
cc%C5
! C%C
) )$') 9$c 5
! c(c
%c) 
c 
c
c
9
'9
(#
'
(##;
) ' 9$(#3

cF 9$5
c

c%c

1/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc
1/cc  c%c
&c
c
cc
%
c! c; cc;19 )$cc"c%c! c
c

c
 
c 
c
)c c%C5
! C%C
) )$')+c!C )$)
c)+c!C
! (c

&c c!C )$)
c)
ccc
4%c4 :)
'!C )$)
c(cc
cc4 "'!C
! (cc%
c
c
2!c!C8
%
!C%
!C!Cc
!C%
cc!C )$)
#8
:
+'c
! (c
!C%
c3c'!C%
D(c
c
 c

!
cc!C%
c
4%c!C
! cc

!
c
c<c!
c
c
$c
%C5
! C%C
) )$
cc%c
c! c
c
c
cLc
$c cc

$c%c


c
%C5
! C%C
) )$cc%
c

c%c
"
$c


c
cF1c c!

c%c%c%C5
! C%C )$
&c!

c
c
1c4%c
1c c
1/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBcc
 
c)+c !"cc,MGc/c0c!!
 c c
)
 c 9$c c;
) cc

Performance increase in table lookup functions QTP

6 c)
c

c 
c%c c c% c c!
c
c
%!
c%c c

 c %+#c4cc
c
c%
c cc&c
cc%cc
c
ccc
;
) )
#c c
c

c% cc
ccc%!cc)
c)c c  c
c
c

c
c)
c'&
c c%c c
c
c
c c
c
!)

c
c
c
c

c! c
c (#c

1$!
c%cc

c +ccc  c

)c c

$4 )
')+
%c)c
$  c)+
%c c)+
%c(c

c cc*cc)# c


ccc*cc)#c
4%c)#8

2' c(cc
$  c
c


$4 )
cc 
c
1$c%c
1c%c
"
$c
"
$c

 cc>*cccc>*c


$4 )
cc 
c
1c c

c$c c  c#8

2c ccc
+c% c!
 cc  cc)
c  c%c@0c c
c*0c! c  c!
 c c

ccc@00c!
cc
c! c 
c
c 
c'c
$c
c%(#c

c% 
c +cc


c
cc c  c
c2!
c:)
c/
c'2:/(#c  c c+c
c
c
c!
c
c

c%cc)
c  c
c %
c%c !
c

c%c
#c

c)
c   c%c c

!
 cc
 c c

!
c c
cc!
c
 #c;
cc


c
!c c
c !
c +c c
cc  c
c%c)
c

)c c

$4 )
2:/')+
%c)c
$  c)+
%c c)+
%c(c

2!c) c)
c

 cc*cccc*c

c
 c) cc)#)
# c
c
 c)cc) #
 c
4%c)#5
cc
$  c
c


$4 )
2:/cc 
c
1$c%c
1c%c
ccc?c*c
"
$c
 cc c?c*c
"
$c

 cc>*cccc>*c


$4 )
2:/cc 
c
1c c

 
c)+c !"cc,*Ic/c0c!!
 c c
)
 c11c cc c;
) )
cc

Importance of Parenthes when we call Function or Sub QTP

;


c+c
%
cc%c  c c!
c + c
%
c
c!
c+
c)+c c
9+5c:c9+
%c9

c%ccc
%
c
c!
c+
c)+c
%cc&
c9+
%c



 c!
cc c'c593(#cc
+c 
+c!&
cc%%


#c2c

)cc%c#c

c  c%%

c)
c)


c

c c%c c
%')(c
c%')(c
 cc!
ccc%c 
c)+c

 c!
 cF
c!
ccc
c
 c
c!
c c)+5c

c%cc c
%
cc
c%c c)+
%#c
1$!
c
)c !
)c'c)(c<ccc)c
c)+c
%c 
c c)+
%c
ccc?c)c

c )c

c  c c 
c
c
cc !
)c
$cc*c
+ccMc
Ncc,c
!
)c$c+c
!
)c'N(c+c
! )$c$c<c + cF@=c
! )$cNc<c + cF,=c)

cNc  c
c c%cc  c
c)+5c


c !
c
c
c+ccc%c

%c !
%'(c
ccOM>*c
!
%cc'c!cMcc*(c

c%c

PccIc
!
%cPc
! )$cPc<c
 c.@c

<c;
c+c
+c%ccc
ccGc
!
%'(c
! )$cc<c
 cGc)

cc c

c)+5c

<c; cc
cc*0c
c !
%'(c
! )$cc<c
 cGGc)

cc c

c)+
%c

<c; ccc!
c

c
cc**c
c !
%'c' (c(c
! )$c c<c
 c**c c c

c)+5c

<ccc c
$!
c%cc%cc  c!
c!
c  c!)
c
c
c!%'c'4!

(c4!6

c(c


cc c
c )K%cc  cc!
cc

c!
c

cc)+
%cc
c%#c
c )K%cc  cc!
cc

c!
c c

c)+
%c)+c
%c
cc
 c

cc
c%c)+cc)+5#c
c
cc c c + c

c)+5#c

3+$c c
: cc c+c)c%c+c
c

 c)

c
+c
cc%c
cc+c c
c
!c
 c 
c)


c
c% cc c!
ccc 
c)


c
c%c

c%'cc)c(c

4%c+c cc
c!
 cc

c!
c+c c
cc 
c)


c
c


 cc
c!
 c)cc
c
!c)


c
c%K )cc
c

 c
)
cc
c%K )cc

%c'(c')(c
c
c%'c'(c')(c(c

Delete Cookies and Temprary internet files VB QTP


!cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc


!c


c&
c

c%C2


) 
 
'2:6/1Q*R631"/1R&
(c


!cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc


!c
!c


c
!+c

c%
c

c%C2


) 
 
'2:6/1Q*R631"/1R Q*
!Q*=(c


!cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

1/c c%C2


) 
 
' (c


!c  c c


c
c%
cLc )%
c
c
c 
%
c c

1/c4c  cc 


c cc
c 
c c

1/c:'
 +
(cc"
c

1/c"
cc4 c%
c

c
cc cc


c  cc1c
1/c

c*SKKM00Gcc !c"cTTc 
//K22KAAAAc

1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

)c c%C2


) 
 
'  (c

c1c
!
c"
$c


!c

c 
c3+ 
!c)
c


c) 
3+ 
!cc

:)
'3# 
3+ 
!:)
F(c


!c

c; c3
c)
c

3
c); 3
cc

:)
'F;3#3
F(c


!c
c 
 c
c  c%
c

c

3
c) 
cc) 
3+ 
!#8
 
'); 3
#1$1!
3 '  ((c


!c
cc
c%
c
c
c%
cccc%c


c
c%
c

c1 c 
c4c) 
#%
c

:c1c
!
c"
$c

) 
3+ 
!#2



c 
c

1#
c

"
$c


!c
cc
c )%
 c
c
c%
cccc%c


c
c )%
 cc

c1 c3) 


c4c) 
#3) 
 c

:c1c
!
c"
$c

) 
3+ 
!#2



c3) 
c

1#
c

"
$c


!c
c
c)
cc

c) 
3+ 
!cc c


c); 3
cc c


c) 
cc c

1#
c

1c%c

 
c)+c !"cc-*,c/c0c!!
 c c
)
 c&
c

:)
'U #%
+ 
!)
U(c 
3+ 
!:)
c3
c

!+c

c%
c;3#3
cc

Close All open Browser QTP VB

<c  c%c
cc
c9
c
1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

1/c  c%c
cc
c)
c

)c c%C
9
'(c
; 
c9
'
 !
0=(#1$ c
9
'
 !
0=(#
c
;
c
1c c

1/c
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB c

 
c)+c !"cc-*Mc/c0c!!
 c c
)
 c c;19cc

Close Application Process QTP

1/c  c%c&c
c
c
c
$
c  c &c!
c

!c
$!
cc%C
'11#11(c

)c c%C
'c)+c 1$
(c
2!c !
c
2!c);/43

c
2!c

c
2!c)
c
!
ccF#c
3
c);/43

cc8
:)
' !! cLc !
cLcF!M=(c
3
c

cc);/43

#1$

+c'3

cBc%!c;@MC
c;

c"!
cc
<L 1$
L<(c
c1 c)
cc

c
)
#
!
'(c
"
$c
3
c);/43

cc" c
3
c

" c
1c c

 
c)+c !"cc-0,c/c0c!!
 c c
)
 c;@MC
c !

cc

Get current DATETIME through VB QTP/Create unique file or folder

Some Time we want create a folder Or File with unique name then we current date time
value for creating the file or folder that we can use this method for create the file OR folder
as decribed herec

1/c  c%c
c
c
c
c!
cc
$c%!c

1/c c%C8
2
!

$'(c  c%c
c

!
cc
$c%!c
1/c  c c
!
c
c 
c c%!c

!
cLc

c  cCc
 
c
1/c4cc"
c
1/c:'
 +
(cc
c

!
cc
$c%!cc

Public Function fn_GetDateTimeTextc

Dim sDateTime
sDateTime = now
sDateTime =replace(sDateTime,´:´,´_´)
sDateTime =replace(sDateTime,´>´,´_´)
sDateTime =replace(sDateTime,´<´,´_´)
sDateTime =replace(sDateTime,´/´,´_´)
sDateTime =replace(sDateTime,´|´,´_´)
sDateTime =replace(sDateTime,´\´,´_´)
sDateTime =replace(sDateTime,´*´,´_´)
sDateTime =replace(sDateTime,´"´",´_´)
sDateTime =replace(sDateTime,´#´,´")
fn_GetDateTimeText =sDateTime
End Functionc

dim sGetCurrentDateTimec

sGetCurrentDateTimeccfn_GetDateTimeText()c

Set objFSO =CreateObject(´Scripting.FileSystemObject´)c



!c

c
$c%
c

objFSO.CreateTextFile(³c:/´ & sGetCurrentDateTime & ³.txt´ , True)c


!c

c%
cc

objFSO.CreateFolder(³c:/´ & sGetCurrentDateTime & ³.txt´ , True)c

 
c)+c !"cc-0Mc/c0c!!
 c c
)
 c

:)
'U #%
+ 
!)
U(c


$ 
c
c":;c c



c!
cc

Check XML File Valid OR Not VB QTP

1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

!c  c c
&c/c 
c5c:cc%c 
ccc/c
c
c 
c1
c

c
1/c c%C
&/5'c /%
 (c
1/c4c /%
 cc/%
 c
1/c:'
 +
(cc 
cc 
c
1/c

cM*KKM00Gcc !c"cTTc 
//K22KAAAAc

1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

)c c%C
&/5')+c /%
 (c

!c

c/c)
c
3
c$!2cc

:)
'cF/ %#/2:/c(c
$!2# +ccF 
c

!cc/c 
c
$!2#'c /%
 c(c
4%c$!2#
1#

EV0c
c
%C
&/5 
c


c
%C
&/5 
c
1c4%c
3
c$!2cc c

1c c

1/cBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBc

 
c)+c !"cc-00c/c0c!!
 c c
)
 c

:)
'cU/ %#/2:/Uc(c c59c/cc

Get Column Address Excel VB / Find Column


Some Time we have to Check that particular column Exist or Not abd required the column
addressc
rem this function return the column address of your Excel sheet
rem input parameter xlFilePath := xls file path || FindColumn =column value which need
to be checkc
dim  cc !c
!
c
 c !"#$ c
!c
%
c$ c%
c c
!cc
!c
&ccc!c
$ ccc

!
ccFindColumnAddress'  c !c(c
! )$c
!
c
Public functioncFindColumnAddress'Byval $ 
 cbyval !c(c

3
c:)1$
cc

:)
'1$
#(c

!c2 )
c
 c
:)1$
#2 +
 cc 
c

!ccc &)&cc
c1$
cc
:)1$
#;&)& #
'$ 
 (c
<8
c
c)
c%c
c% c

cc
c &)&c
3
c)
3

cc:)1$
#3

 '3

*=(c

!cc
c!cc

c
!c)
3

#6

#! #c

!c
c
c c!c
c
c

')
3

#
 '*!(#
WU(c

!c
%
c
c
c%!c*cc c!c
cc%c
c
cc
c

c)5
cc)
3

#
'*L(# ' !(c
4%cc)5
c c c
c
!
c

')5
#
WU(c
!
c

' !
*=U(c
Exit functionc

End Ifc

!c%cc%c
c
c
c1!+c
!
c": c :6"2c

Set )5
c c
Set )
3

c c
Set :)1$
c c
End Functionc