How To Use Sendkey Function in QTP or UFT or VBScript?

0
60
Spread the love
  • 11
  • 12
  • 8
  • 15
  •  
  •  
  •  
  •  
  •  
  •  
    46
    Shares

How To Use Sendkey Function in QTP or UFT or VBScript

Sendkey– the term says us that this is related to some key which needs to be sent. Now Questions are where ?? when?? how??
Consider a scenario when you need to delete a few things from your drive or you need to select all the files or you need to take a screenshot automatically through scripting.
There might be a scenario where QTP/UFT fails to record a step and still you need to automate that scenario.

How do you go through manually…yes by keying Delete key or Alt+A or by pressing PrtSc.
Right Now if the same has to done through QTP/UFT, we need to educate QTP regarding the same. Well, most of the time, we need to use sendkey function while doing an end to end Testing…I am not going in depth of idea… let’s go directly to the point…I am incorporating some basic codes which can be used.

Let’s check out how to write a small function that does our work…


Sub ctrlA()
//This is for Ctrl+a command
set WshShell = CreateObject("WScript.Shell")
WshShell.Sendkeys "^"+"{a}"
set WshShell = Nothing
End Sub
 

Let’s see some more example…


Sub shiftDel()
//this is for Shift delete command
set WshShell = CreateObject("WScript.Shell")
WshShell.Sendkeys "+"+"{DEL}"
set WshShell = Nothing
End Sub
 

Yes, you got the idea right…Now u need the list of all keys which can be sent during the runtime.
Click on the link:http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
to get the list of all keys that can be sent.

This is a very popular solution while working with UFT and advanced framework. Also, read VBScript Datatype for further understanding. While working with sendkeys don’t forget to use comments for readability.

Happy sending..:)

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 11
  • 12
  • 8
  • 15
  •  
  •  
  •  
  •  
  •  
  •  
    46
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here