How to select all text using UFT- CTRL+A and CTRL+C method

There may be some instances where you need to copy and paste or select all text using UFT. You can achieve this in many ways. One important method is to replicate what we do manually. Yes! you guessed it right. By using Ctrl+A and CTrl+C with vbscript code.

QTP or UFT provides an inbuilt object Mercury.Clipboard which can be used to replicate all operations for the clipboard. Here we will create two objects

  • Mercury.Clipboard – to access the copied text
  • Mercury.DeviceReplay – to replicate keyboard operations

Example code to select all text using UFT – Ctrl+A Ctrl+C method

Function getText_CtrlA_CtrlC()
	Set objClip= CreateObject("Mercury.Clipboard")	
  Set DeviceReplay = CreateObject("Mercury.DeviceReplay")
  objClip.Clear
  Const VK_CONTROL = 29
  Const VK_A = 30
  Const VK_C = 46

	DeviceReplay.KeyDown VK_CONTROL
	Wait 0,600
	DeviceReplay.PressKey VK_A
	Wait 0,600
	DeviceReplay.KeyUp VK_CONTROL
	Wait 0,600	 
	DeviceReplay.KeyDown VK_CONTROL
	Wait 0,600
	DeviceReplay.PressKey VK_C
	Wait 0,600
	DeviceReplay.KeyUp VK_CONTROL
	Wait 0,600
	getText_CtrlA_CtrlC= objClip.GetText
	
	Set objClip= Nothing
	Set DeviceReplay= Nothing
End Function

You may also read


Discover more from Automation Script

Subscribe to get the latest posts sent to your email.

Related Posts