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.
Code:-
systemutil.Run “notepad.exe”
‘Fucntion call
fnNotepad(“Help”)
Public Function fnNotepad(sFileName)
‘Writing into Notepad
Set objNotpad = Window(“regexpwndtitle:=Notepad”,“regexpwndclass:=Notepad”)
objNotpad.WinEditor(“nativeclass:=Edit”).Type “Welcome to uftHelp”
objNotpad.WinEditor(“nativeclass:=Edit”).Type micCtrlDwn + “s” +micCtrlup
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
objNotpad.Close
Set objNotpad = nothing
End Function