Working with Notepad in UFT/QTP

Scenario:– Launching Notepad and writing data , saving and closing at the end.

Working with Notepad in UFT

Solution:– For understanding purposes I’ve used “Descriptive Programming“(We can easily use objects saved in Object Repository).

Copy the below code and run in UFT/QTP to understand the flow.

Further  we can also close all the notepad instances opened before launching the new instance through our script. We are closing it, so that previous notepad applications don’t interfere with script execution.


‘Launching the Notepad Application
systemutil.Run “notepad.exe”

‘Fucntion call

Public Function fnNotepad(sFileName)
‘Writing into Notepad
Set objNotpad = Window(“regexpwndtitle:=Notepad”,“regexpwndclass:=Notepad”)
objNotpad.WinEditor(“nativeclass:=Edit”).Type “Welcome to uftHelp”

‘Saving and closing the notepad
objNotpad.WinEditor(“nativeclass:=Edit”).Type micCtrlDwn + “s” +micCtrlup
‘Filling the filename 
objNotpad.Dialog(“text:=Save As”,“nativeclass:=#32770”).winEdit(“nativeclass:=Edit”,“attached text:=File &name:”).Set “C:Documents and SettingsdhesiDesktop”&sFileName

objNotpad.Dialog(“text:=Save As”,“nativeclass:=#32770”).winbutton(“text:=&save”,“nativeclass:=Button”).Click

‘Closing the notepad
‘Destroying the object
Set objNotpad = nothing

End Function