1

I'm trying to automate UI of an extension (WPF) in Visual Studio 2017 using WinApp Driver but cannot find automation id when capturing elements using Inspect.exe (Windows SDK)

Initially there were no automation id's found when inspected by Inspect.exe. So I set the automation id in the XAML file, in its automation properties and installed the new VSIX back in Visual Studio, but still the above set ids were not visible when capturing elements.

But after I attempt to capture the UI objects after setting id/s in the XAML as above described, using inspect element tool, sporadically automation id was appeared but it was not consistent and I could not find the reason why it was not available/visible consistently.

I was succeeded in some scenarios by using 'FindElementByName' and 'FindElementByClassName' but my intention is to use automation id to capture elements more accurately.

Below is the XAML code where I have Set AutomationId;

Button Content="Close" Width="80" Height="25" Margin="10,0,0,0" Visibility="{Binding abc}" Click="CloseButton_Click" AutomationProperties.AutomationId="BtnCloseExample"

Below is the code line where I set the id to capture the element in my test project;

session.FindElementById("BtnCloseExample").Click(); Thread.Sleep(TimeSpan.FromSeconds(3));

I expect a consistent way to set and get the automation id in order to use FindElementById or xpath. Sadly, I could not find good articles related to this issue as well.

Please shed some light and provide some guidelines to achieve this task. It would be utterly valuable if some one can publish a sample of automating wpf application, if possible.

Thank you.

hiran91
  • 31
  • 6
  • I know a few things that could cause these symptomes. 1. If the controls get declared in code (not XAML), you won't have Id's available, since you declare them in the XAML. 2. Make sure you use the correct windowhandle, perhaps it's the wrong one? You'll need to check the page source for that. See 'session.getPageSource()', it's XML. 3. For some unknown reason, the changes you made to the source weren't compiled in the program you are testing. – PixelPlex Aug 22 '19 at 06:58
  • If you're looking for winappdriver resources, I have good experiences with their [Github](https://github.com/microsoft/WinAppDriver). – PixelPlex Aug 22 '19 at 13:41
  • Hi @PixelPlex thank you for the idea given. I will try it today and see for an improvement accordingly. Cheers! – hiran91 Aug 23 '19 at 04:23

1 Answers1

1

If you are trying to locate UI element by automation ID, you should use FindElementByAccessibilityId instead of FindElementById (which will look for runtime ID) as documented here: https://github.com/microsoft/WinAppDriver#supported-locators-to-find-ui-elements

popsiporkkanaa
  • 678
  • 1
  • 9
  • 17
  • Hi @popsiporkkanaa I have used FindElementByAccessibilityId since the beginning but did not work as expected. – hiran91 Aug 23 '19 at 04:25
  • If you can capture the button in inspect tool, can you add a screenshot/ description of the button relation with its ancestor/children element in the UI element tree? – popsiporkkanaa Aug 23 '19 at 05:55