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. In the Silk4J tool bar, click 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. If you are testing a web application on Microsoft Edge, Mozilla Firefox, Google Chrome, or Apple Safari, select the Recording Mode:
    • Select Record Silk Test Locators to record locators that you can use with Silk4J.
    • Select Record WebDriver Locators to record locators that you can use with Selenium WebDriver.
    Note: When recording WebDriver locators, a ">" in the object tree denotes switching from one IFrame to another.
  5. Optional: To display locators in the Locator column instead of object map items, uncheck the Show object map identifiers check box. This setting is not available when recording WebDriver locators. 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.
  6. 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.
  7. 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.
  8. Optional: Click Show additional locator attributes to display any related attributes in the Locator Attribute table.
  9. 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.
  10. If you are recording WebDriver locators, select the locator type for the Selected Locator:
    • XPath locator. Identifies the control by combining the name of the control class and a collection of prioritized attributes into a unique locator. If the combined locator does not unequally identify the control, Silk4J additionally adds an index to the locator or prefixes a parent UI control by using "//".
    • Locate by id. Identifies the control by the id attribute.
    • Locate by name. Identifies the control by the name attribute.
    • Locate by link text. Only for hyperlinks.
  11. 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.
  12. 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.

  13. Copy the locator or the object map item to the test case or to the Clipboard.
  14. Click Close.