QuickTest Pro: Working with the Windows Clipboard (Clear, Copy and Paste Text)

QuickTest Pro can interface directly with the Windows OS clipboard during replay using the VBScript “Mercury.Clipboard” object built in to QTP. This object can be used to validate clipboard data if the AUT programmatically manipulates the clipboard (and your test case requires validation of this functionality).

Some of the more common methods supported in the “Mercury.Clipboard” object include:

  • Clear – clear the clipboard contents
  • SetText – write text to the clipboard
  • GetText – retrieve text from the clipboard

Some of other methods documented in My.Computer.Clipboard object are also supported.

Below is an example of clearing, setting and retrieving text in the clipboard:

Option Explicit
Dim objCB
Set objCB = CreateObject("Mercury.Clipboard") 
objCB.SetText "Data in clipboard set by QTP"
MsgBox objCB.GetText
Set objCB = Nothing

It is very important to note that sensitive data should not be stored in the clipboard because the content may be accessible by other users.

What other methods have you implemented to interact with the Windows clipboard?

What's Next?

Did you enjoy this article? Help spread the word by sharing:

Join the Northway Navigator Club today and get access to restricted content including our best tips and tricks. Membership is free! You will also receive free email updates by registering.

Engage in the conversation and leave a comment:

Brian MacKenzie

About Brian MacKenzie (24 articles)

Brian has over 14 years of experience working in IT, ranging from Software Quality Assurance, Software Development, Business Management to Systems Administration, in a wide range of technologies, languages, databases, systems and software. He has experience in both software quality assurance and software development roles. Brian specializes in HP LoadRunner, HP UFT (QuickTest Pro and Service Test), Mobile Testing and Automation, HP ALM and HP Service Virtualization, as well as delivering certified instructor training in HP UFT and mentoring in Service Test and Service Virtualization.

  • Ross

    Hi Brian,

    How can I copy and paste using devicereply or clipboard? Please share if you have a solution. I just need to paste on a webedit field after copying from a webtable. Thanks in advance!!


    • Brian MacKenzie


      You can copy with the clipboard using the code in this post. I will add the DeviceReplay topic to a list of possible future blog article topics. Thanks for the question!