Adding a Locator or an Object Map Item to a Test Method Using the Locator Spy

Manually capture a locator or an object map item using the Locator Spy and copy the locator or the object map item to the test method. For instance, you can identify the caption or the XPath locator string for GUI objects using the Locator Spy. Then, copy the relevant locator strings and attributes into the test methods in your scripts.
  1. Open the test class that you want to modify.
  2. Click Silk4NET > Locator Spy.
    The Locator Spy and the application under test open. If you are testing a mobile application, a recording window opens, representing the screen of the mobile device. You cannot perform actions in the recording window, but you can perform actions on the mobile device or emulator and then refresh the recording window.
  3. Optional: To bring the application under test into the appropriate state before recording a locator, click Stop Recording Locator. The actions that you perform in the application under test are no longer recorded. To continue with the recording of a locator, click Start Recording Locator.
  4. Optional: To display locators in the Locator column instead of object map items, uncheck the Show object map identifiers check box. Object map item names associate a logical name (an alias) with a control or a window, rather than the control or window's locator. By default, object map item names are displayed.
    Note: When you check or uncheck the check box, the change is not automatically reflected in the locator details. To update an entry in the Locator Details table, you have to click on the entry.
  5. Position the mouse over the object that you want to record. The related locator string or object map item shows in the Selected Locator text box.
    Note: If you are testing on a browser, the Selected Locator field displays the locator only when you actually capture it.
  6. Press Ctrl+Alt to capture the object.
    Note: Press Ctrl+Shift to capture the object if you specified the alternative record break key sequence on the General Recording Options page of the Script Options dialog box.
  7. Optional: Click Show additional locator attributes to display any related attributes in the Locator Attribute table.
  8. Optional: You can replace a recorded locator attribute with another locator attribute from the Locator Attribute table. For example, your recorded locator might look like the following:
    /BrowserApplication//BrowserWindow//input[@id='loginButton']
    If you have a textContents Login listed in the Locator Attribute table, you can manually change the locator to the following:
    /BrowserApplication//BrowserWindow//input[@textContents='Login']
    The new locator displays in the Selected Locator text box.
  9. To copy the locator, click Copy Locator to Clipboard. In the Selected Locator text box, you can also mark the portion of the locator string that you want to copy, and then you can right-click the marked text and click Copy.
  10. In the script, position your cursor to the location to which you want to paste the recorded locator. For example, position your cursor in the appropriate parameter of a Find method in the script.

    The test method, into which you want to paste the locator, must use a method that can take a locator as a parameter. Using the Locator Spy ensures that the locator is valid.

  11. Copy the locator or the object map item to the test case or to the Clipboard.
  12. Click Close.