Reputation: 421
I'm new to Ranorex and trying to use Ranorex's C# API for a Windows desktop application. How to find an element only by automation id/text in C#?
Looking for something like,
mainWindow.Get(SearchCriteria.ByAutomationId("<automationId>"))
mainWindow.Get<Button>("<automationId>");
or
mainWindow.Button.GetElement("<automationId>");
But in the API docs, all I can see is XPath (RanoreXPath) based object identification.
Upvotes: 1
Views: 6949
Reputation: 677
To help find the XPath syntax to find an element, it is highly recommended to use the Ranorex Spy (would save you a lot of time).
I would also recommend using the recorder instead of directly user code, as it greatly simplifies automated tests maintenance… (and facilitates learning Ranorex). BTW, if you create a recording using the recorder and open its corresponding source file, you will see the equivalent code required to do whatever action you recorded. Saves lots of time when developing user code…
Hope this points you in the right direction.
Upvotes: 1
Reputation: 633
Do you know where it's located (approximately)? If you do, open SPY and click "Track", then click on that area where your element is located. In SPY, navigate to tab "BROWSER & RESULTS" and look through the tree. On the right side, you can see tabs "Overview/Advanced", while in Advanced tab scroll to bottom and look for Name of your element.
Also, you can try this: Edit the path to your element and hit "Apply". For example, as suggested above – use .//text[@automationid='DealerNameText']
or .//button[@automationid='ButtonPause' and @visible='true']
that depends on your element. Check this out, helped me a lot.
Upvotes: 0