How to: Select a Control Using the Keyboard in Coded UI Tests
You can use the Coded UI Test Builder to add a user interface (UI) control to the UIMap for your coded UI test, or to generate code for a validation method that uses an assertion for a UI control. In addition, you can add a UI control for the application under test to an existing UI map by using the crosshair tool in the Coded UI Test Builder. Alternatively, you can choose the control with the mouse and then press the Windows logo key + I. For more information about using the crosshair tool, see How to: Add UI Controls and Validation Code Using the Coded UI Test Builder.
Sometimes, using the keyboard might be necessary. For example, when you attempt to record a coded UI test that uses a context menu control, the list of menu items in the control will lose focus and disappear when you try to select the crosshair tool from the Coded UI Test Builder.
To select a control using the keyboard in coded UI tests
Generate your coded UI test. For more information, see How to: Generate a Coded UI Test by Recording the Application Under Test.
When you perform your coded UI test, while hovering over the control, press and hold the Windows logo key. At the same time, press and hold the I key. Release the keys. The control is recorded by the Coded UT Test Builder.
If you use Microsoft Lync, you must close Lync before you start the Coded UI Test Builder. Microsoft Lync interferes with the Windows logo + I keyboard shortcut.
Although the keyboard is one way you can select any control in a coded UI test, sometimes it is the only way. Occasionally, the control loses focus when you use the crosshair tool in the Coded UI Test Builder. For example, in the following illustration, the context menu in Windows Internet Explorer would typically lose focus and disappear if you tried to select it with the crosshair tool.