Reputation: 31
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.
Upvotes: 1
Views: 2817
Reputation: 748
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
Upvotes: 1