How To Use WinAppDriver UI Recorder to Record xPath

How To Use WinAppDriver UI Recorder to Record xPath

Why You Might Use WinAppDriver (WAD) UIRecorder

Cycle native app steps using WinAppDriver allow for the use of several object locator types to identify objects within the app.

Whenever possible, it is best to identify application objects using the WinAppDriver supported locator types: id, automationID, name, or controlType. However, sometimes you may find it necessary to identify native app objects using the xPath locator type when the supported locator types are not unique for a specific application object.

For example, there may be several objects using the same locators within the same application but in different forms, panes, or data grids. In those instances, you will more than likely need to use xPath to identify the location of those objects and ensure Cycle is interacting with the correct object.

The syntax of xPath in native app steps is similar to the syntax in web steps. Tools such as the Inspect Console within the Chrome web browser are useful to help construct and validate xPaths for web driver steps, but there is no similar tool included in Inspect.exe.

There is a separate tool called WinAppDriver (WAD) UI Recorder that can be used to retrieve an absolute xPath that WinAppDriver can use to locate an object. WAD UI Recorder will record the absolute xPath for an application object on mouse hover or click. You can then make some slight modifications to the recorded absolute xPath for use within your Cycle step.

You can also use the absolute xPath recorded in WAD UI Recorder to help you construct a relative xPath that may be more readable and manageable within your Cycle steps.

The WAD UIRecorder download can be found here.

Steps for Recording an Absolute xPath

It is important to always run WAD UI Recorder as administrator. You may not be able to record object xPaths in some applications if you are not running WAD UI Recorder as admin.

The absolute xPath recorded by the tool is not immediately usable in your Cycle step. There are some modifications that need to be made to the xPath to make it usable within Cycle.

  • Run WAD UI Recorder as administrator. The application window below will open on your desktop.

UIRecorder_Open.PNG

The top panel will display the absolute xPath recorded by the application. This is where the xPath we will use in Cycle is generated.

The bottom panel displays xPath node information.

There are also buttons located at the bottom of the window used to Record and Clear the panels. The Record button will change to a Pause button while recording is in progress.

 

  • Click the Record button to start recording xPath. The WAD UI Recorder will now start recording xPaths of any object you interact with on your desktop.

 

  • Hover your mouse over or click on the object in your target application to generate the absolute xPath. The xPath appears in the top panel of WAD UI Recorder. Clicking Pause will stop WAD UI Recorder from recording xPath for any additional objects clicked on your desktop.

Object clicked:

Click_Application_Object.PNG

xPath recorded in WAD UI Recorder:

xpath_recorded.PNG

"/Window[@Name='JDA Solutions'][@AutomationId='frmDLx']
/Group[@AutomationId='pnlBackground']/Group[@AutomationId='pnlGradient']
/Group[@AutomationId='pnlHost']/Pane[@AutomationId='controlHost']
/Pane[starts-with(@AutomationId,'shpmstdsp')]/Pane[@AutomationId='pnlRecord']
/Tab[@AutomationId='tabDtl']/Pane[@Name='Inventory']
[@AutomationId='tabInventory']/Custom[@AutomationId='gridInvLoads']
/Table[@Name='MainView'][@AutomationId='GridView:Parent=Control']
/DataItem[@Name='0'][starts-with(@AutomationId,'Row:Handle=')]
/Text[@Name='0'][@AutomationId='Cell:Row=0,Column=0']"

The absolute xPath will need to be modified in order to use it in your Cycle native app step. You will need to replace the escaped double quote characters with single quotes and change the starting point of the xPath.

  • Copy the xPath from the top panel of WAD UIRecorder and paste it into your text editor of choice.

xpath_pasted_pre_edit.PNG

  • Find all instances of escaped double quotes (  \" ) and replace with single quotes ( ' )

xpath_remove_double_quotes.PNG

  • Remove the "Desktop" portion from the absolute xPath. This portion of the xPath is not necessary and will cause WinAppDriver to not find the object because you have already connected directly to the application within Cycle.

The portion of the xPath you need to remove is highlighted below:

xpath_pre_remove_desktop.PNG

The xPath should look like this after modification:

xpath_final.PNG

  • Copy and paste the xpath into your Cycle step. Be sure to include the 'xPath:' locator type before the xPath itself.

cycle_step.PNG

  • The Cycle can now find your object within the application.

absolute_output.PNG

Creating a Relative xPath

You can also use WAD UI Recorder to help you build a relative xPath. You may find relative xPath to be easier to read and manage within your features.

Follow the steps above to format the absolute xPath properly for your Cycle step. Then search for opportunities to eliminate unnecessary portions of the xPath while still ensuring your relative xPath will allow Cycle to identify the correct object.

Here is a relative xPath identifying the same application object that we identified using the absolute xPath we previously recorded.

"//*[@Name='JDA Solutions']//*[starts-with(@AutomationId,'shpmstdsp')]
//*[@AutomationId='tabInventory']//*[@AutomationId='gridInvLoads']
//*[@Name='MainView']//*[@AutomationId='Cell:Row=0,Column=0']"

Copy and paste the relative xPath into your Cycle step.

relative_xpath_step.PNG

Cycle can now see the object using the relative xPath.

relative_xpath_output.PNG

    • Related Articles

    • How to Use xPath With Native App Steps

      Native app steps and xPath Cycle native app steps (using WinAppDriver) allow for the use of several object locator types to identify objects within the app. Whenever possible, it is best to identify application objects using the WinAppDriver ...
    • How To Find Windows AppID for Native App Steps

      Windows applications built using the Universal Windows Platform (UWP) API require Cycle to open the application using the AppID of the application rather than than specifying the executable application as needed when opening Classic Windows (Win32) ...
    • How To Decide When to Use Native App Steps

      Beginning with Cycle 2.4, Cycle now has the ability to interact with native Windows applications by using the WinAppDriver (WAD). These new native app steps allow Cycle to interact with Windows applications without relying on desktop steps that are ...
    • How to use Inspect.exe and Locator Types with Native Apps

      To use Cycle native app steps, it is recommended that Window’s Inspect.exe is used to identify app Object Identifiers.  It is recommended to use Inspect.exe with multiple monitors. If you have not downloaded and installed Inspect.exe, follow the ...
    • How To Configure Your Computer to use Cycle's Native App Steps

      Beginning with version 2.4, Cycle adds a new set of steps designed for interacting with native applications on your computer in specifically targeted ways. In order to use these steps, you will need to take the following steps on your machine:   Step ...