0

How can I locate XPath for an element in desktop application

I am using Inspect tool to get the Name of an element. How do I create an Xpath from the Inspect tool? Can I use LegacyIAccessible.ChildId in the XPath to locate the location of the element.

'How found: Mouse move (-1648,104)'
'Name:  "Compare"'
'ControlType:   UIA_ButtonControlTypeId (0xC350)'
'LocalizedControlType:  "button"'
'BoundingRectangle: {l:-1695 t:94 r:-1587 b:116}'
'IsEnabled: true'
'IsOffscreen:   false'
'IsKeyboardFocusable:   true'
HasKeyboardFocus:   false
'AccessKey: "Alt, C, CP"'
'ProcessId: 22040'

'IsPassword:    false'
'HelpText:  ""'
'IsDialog:  false
'LegacyIAccessible.ChildId: 3'
'LegacyIAccessible.DefaultAction:   "Press"'
'LegacyIAccessible.Description: "Compare the Controller Strategy with the PC"'
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
tester
  • 3
  • 1
  • 3
  • 1
    XPath is for locating positions/elements inside XML/XHTML DOM and the like, essentially a web page or file. Not applicable to conventional desktop apps. – ou_ryperd Nov 12 '19 at 10:58
  • Yes you are right . It is used to find web elements. It can also be used in winium which is used for Desktop Applications. See : https://github.com/2gis/Winium.Desktop/wiki/Finding-Elements – tester Nov 13 '19 at 11:48
  • @ou_ryperd Winappdriver supports a tree structured approach windows desktop automation. It is possible to make use of XPath selectors. – sphennings Nov 15 '19 at 20:04
  • @sphennings I didn't know that. – ou_ryperd Nov 16 '19 at 19:32
  • Do you need to use an XPath selector? I've found that using AutomationID leads to more reliable and faster tests of desktop applications. – sphennings Nov 18 '19 at 16:06
  • @sphennings Yes I want to use XPath. I am using Winium for my desktop application. Can I use the same selector the WinApp Driver is using to get the XPath? – tester Nov 20 '19 at 07:27
  • Winnium and Winappdriver don't make any guarantees of compatibility. I'd recommend only working with one driver to prevent confusion. – sphennings Nov 20 '19 at 17:50

2 Answers2

0

you can use appium to get the current session. Once the appium grabs the current window, you can use is to find the xpath. I am using appium

-Open Appium 
-go to file  
-New session window 
-attach to session 
-paste the session (make sure your app is in debugging mode and your session    is active) 
-appium will grab the current window of the desktop app
kishor sharma
  • 179
  • 2
  • 17
0

Use the WinAppDriver UI Recorder, it is available in WinAppDriver GitHub repository. When UIR is running, it generates the XPath to reach any UI element you hover the mouse on.enter image description here

tester
  • 3
  • 1
  • 3
Naeem A. Malik
  • 995
  • 4
  • 19
  • Thanks for that. I have the Win App Driver Ui Recorder. But not sure how I can generate the XPath. Is there any combinations I can use to create it? I don't see a tag called xpath. – tester Nov 20 '19 at 07:51