Awesum Stuff

How to Automate Windows Clipboard

Ever felt the need to extract the contents of the Clipboard ? In case you did, this article is perfect for you (but in case you didn’t, you might feel like doing it coz its so cool !!!). So here’s the code to get you started with it :-

Set myClipBoard = CreateObject(“Mercury.Clipboard”)        ‘Creating the Clip Board Object

myClipBoard .Clear          ‘Clears the Current Contents of the Clip Board

myClipBoard .SetText “TEST”      ‘Puts the specified String onto the Clip Board

msgbox myClipBoard .GetText             ‘Fetches the Current Contents of the Clip Board

So basically I came across an Application wherein QTP was not able to recognize the inner contents of an Object. I tried two ways for solving this issue :-

1. Using the Native Method called GetVisibleText on the Object. It gives me all the text currently displayed on the object. Although this approach is fine in many cases, it didn’t work in my case as I wanted to capture some part of the text and another issue was that it was not converting the text properly. For eg : “Shape 1” was displayed as “Shape !”

2. Using the Clipboard – This works fine in this case. Basically the object I’m talking about is a SwfGrid and I needed to navigate to a particular row and then fetch the contents. So first of all I used the Type method in the following way :-

Window(“name:=Dummy”).SwfObject(“name:=Dummy”).Type micDwn  ‘Simulates Keyboard’s Down Key

Window(“name:=Dummy”).SwfObject(“name:=Dummy”).Type micCtrlDwn + “c” + micCtrlUp   ‘Simulates Ctrl + C

Set myClipBoard = CreateObject(“Mercury.Clipboard”)

myString=myClipBoard.GetText           ‘myString contains the Contents of the currently Active row in the SwfObject

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s