31 Dec 2013

Unknown QTP Webtable Methods

CellText
This method works as same as GetCellData method.
Eg.: Msgbox Browser("name:=qtp").WebTable("index:=0").CellText(1,1)  

CellTextByContext 
This method returns the text within a cell delimited by a character. We can retrieve the text before (or) after the delimiter using this method.
Eg.: Consider a cell having the text “Prime;Venkat”. Here “;’ is the delimiter

Code to retrieve the text before the delimiter
Msgbox Browser("name:=qtp").WebTable("index:=0").CellTextByContext(1,1,"",";")  

Code to retrieve the text after the delimiter
Msgbox Browser("name:=qtp").WebTable("index:=0").CellTextByContext(1,1,";")  

TextCellExist
This method checks whether a text exists in a cell or not. It returns true, if the input text exists in the cell, else it returns false. Rather than using GetCellData method and then comparing the result with the input text, we can achieve it using this simple method.
Msgbox Browser("name:=qtp").WebTable("index:=0").TextCellExist(1,1,"Prime") 


I hope this is useful to you all.

18 Nov 2013

How to kill the processer from Task Manager in QTP

How to kill the processer from Task Manager

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'excel.exe'" 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next 
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WScript.Quit 

Display the Unique values and delete the duplicate values in an array using Vb Scripting

Display the Unique values and delete the duplicate values in an array using Vb Scripting

Dim arr, res(8), temp, count1 

count1=0

arr=array(0,12,47,58,21,12,0,47,69)

For i=lbound(arr) to ubound(arr)
    
temp=i

    For j=i+1 to ubound(arr)

        If arr(i)<>arr(j) Then

            temp=temp+1

        End If
    Next
    If temp=ubound(arr) Then
        res(count1)=arr(i)
        count1=count1+1

    End If

Next

For i=0 to count1-1
   msgbox res(i)
Next

Print the duplicate values in an array

Print the duplicate values in an array

x=array(5,8,6,2,4,7,9,5,6,8,0)

For i=0 to UBound(x)

If instr(b,x(i))=0 Then

b=b&x(i)

ElseIf instr(b,x(i))>0 then

msgbox x(i)

End If

Next

Recursively List All Files and SubFolders Inside a Folder

Recursively List All Files and SubFolders Inside a Folder at Any Level Depth

Dim fso
Dim ObjOutFile

'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Create an output file
Set ObjOutFile = fso.CreateTextFile("OutputFiles.csv")

'Writing CSV headers
ObjOutFile.WriteLine("Type,File Name,File Path")

'Call the GetFile function to get all files
GetFiles("D:\QTP/Materials")

'Close the output file
ObjOutFile.Close

WScript.Echo("Completed")

Function GetFiles(FolderName)
    On Error Resume Next
     
    Dim ObjFolder
    Dim ObjSubFolders
    Dim ObjSubFolder
    Dim ObjFiles
    Dim ObjFile

    Set ObjFolder = fso.GetFolder(FolderName)
    Set ObjFiles = ObjFolder.Files
     
    'Write all files to output files
    For Each ObjFile In ObjFiles
        ObjOutFile.WriteLine("File," & ObjFile.Name & "," & ObjFile.Path)
    Next
     
    'Getting all subfolders
    Set ObjSubFolders = ObjFolder.SubFolders
     
    For Each ObjFolder In ObjSubFolders
        'Writing SubFolder Name and Path
        ObjOutFile.WriteLine("Folder," & ObjFolder.Name & "," & ObjFolder.Path)
         
        'Getting all Files from subfolder
        GetFiles(ObjFolder.Path)
    Next
     
End Function

Script to List all Immediate Folders Inside a Folder

 Script to List all Immediate Folders Inside a Folder

Dim fso
Dim ObjFolder
Dim ObjOutFile
Dim ObjSubFolders
Dim ObjSubFolder

'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Getting the Folder Object
Set ObjFolder = fso.GetFolder("D:\QTP")

'Creating an Output File to write the Folder Names
Set ObjOutFile = fso.CreateTextFile("D:\QTPsFiles.txt")

'Getting the list of SubFolders
Set ObjSubFolders = ObjFolder.SubFolders

'Writing Name and Path of each Subfolder to Output File
For Each ObjSubFolder In ObjSubFolders
    ObjOutFile.WriteLine(ObjSubFolder.Name & String(50 - Len(ObjSubFolder.Name), " ") & ObjSubFolder.Path)
Next

ObjOutFile.Close

Script to List all Immediate Files Inside a Folder

Script to List all Immediate Files Inside a Folder

Dim fso
Dim ObjFolder
Dim ObjOutFile
Dim ObjFiles
Dim ObjFile

'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")

'Getting the Folder Object
Set ObjFolder = fso.GetFolder("D:\Bills")

'Creating an Output File to write the File Names
Set ObjOutFile = fso.CreateTextFile("D:\BillsFiles.txt")

'Getting the list of Files
Set ObjFiles = ObjFolder.Files

'Writing Name and Path of each File to Output File
For Each ObjFile In ObjFiles
    ObjOutFile.WriteLine(ObjFile.Name & String(50 - Len(ObjFile.Name), " ") & ObjFile.Path)
Next

ObjOutFile.Close