Automating MS Word Ribbon

In this example, we will be automating the clicking on the various  Font buttons in the Microsoft Word ribbon:

Instead of learning the Bold, Italic, Underline, etc. buttons individually, we want to click on them dynamically in a loop.

To do this, we first need to use Rapise's recorder to Learn the overall Font part of the ribbon. The easiest way to do this is to use the UIAutomation Spy during recording and click CTRL+G to track the exact item:

This will then get recorded in the Rapise Object tree as a generic UIAutomation desktop object:

Now that we have the object recorded, we can now use RVL to create the code to dynamically click on a child element using DoFindByText(...) and DoClick()

Creating the Rapise Visual (RVL) Script

Using RVL variables, we can simply call the function to get the child element by name and then click on it.

For example, if we wanted to click on the Bold button we would use:

Finally, we need to create a RVL Map with the various buttons we want to click on and then replace the string containing "Bold" with the value from the Map:

When you play this test it will click on the Bold, Italic and Underline buttons in the MS-Word ribbon in turn.

You can download the full sample code from this link: /Support/Attachment/138214.aspx