This is a migrated thread and some comments may be shown as answers.

Can't find controls by AutomationID

3 Answers 759 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 30 Aug 2018, 08:02 PM

I am attempting to find controls in my WPF application using Automation IDs and it seems my test is not able to find them for reasons I do not understand. This is happening with every control I have tried so far. Other frameworks I am evaluating (Coded UI, White) are able to find the controls using Automation IDs without issue, so I am not sure why Telerik cannot.

 

All I am trying to do here is launch the application and then click the "X" button in the top right to exit it. Here is my code:

 

Settings settings = new Settings();
Manager manager = new Manager(settings);
manager.Start();
var startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = <REDACTED>;
startInfo.FileName = <REDACTED>;
Process process = Process.Start(startInfo);
Thread.Sleep(1000);
manager.ConnectToApplication(process);
WpfWindow mainWin = manager.ActiveApplication.MainWindow;

mainWin.Find.ByAutomationId<Button>("PART_CloseButton").User.Click();

 

And here is the error information:

 

Test Name:    TelerikTest
Test FullName:    TelerikTest.UnitTest1.TelerikTest
Test Source:    C:\git\UITestPrototype\TelerikTest\UnitTest1.cs : line 18
Test Outcome:    Failed
Test Duration:    0:00:34.0393404

Result StackTrace:    
at ArtOfTest.Common.WaitSync.CheckResult(WaitSync wait, String extraExceptionInfo, Object target)
   at ArtOfTest.Common.WaitSync.For[T](Predicate`1 predicate, T target, Boolean invertCondition, Int32 timeout, WaitResultType errorResultType)
   at ArtOfTest.WebAii.Silverlight.VisualWait.ForExistsInternal(Int32 timeout, Boolean invertCondition)
   at ArtOfTest.WebAii.Silverlight.VisualWait.ForVisible(Int32 timeout)
   at ArtOfTest.WebAii.Silverlight.VisualFind.ReturnOrThrow(FrameworkElement e, String throwMessage)
   at ArtOfTest.WebAii.Silverlight.VisualFind.ByAutomationId(String id, String xamlTag)
   at ArtOfTest.WebAii.Silverlight.VisualFind.ByAutomationId[T](String id)
   at TelerikTest.UnitTest1.TelerikTest() in C:\git\UITestPrototype\TelerikTest\UnitTest1.cs:line 33
Result Message:    
Test method TelerikTest.UnitTest1.TelerikTest threw exception:
ArtOfTest.Common.Exceptions.FindElementException: Element Not found!
FindExpression used:
[automationid 'Exact' PART_CloseButton] AND [xamltag 'Exact' Button]

 

For reference, here is the failing line of code written using White:

 

mainWin.Get<Button>(SearchCriteria.ByAutomationId("PART_CloseButton")).Click();

 

This code works perfectly so I know it is not a problem with the control not being there or the automation ID being wrong.

 

Does anyone have any idea what my problem could be? Thanks.

3 Answers, 1 is accepted

Sort by
0
Elena
Telerik team
answered on 03 Sep 2018, 04:00 PM
Hello Alex,

Thank you for sharing details on the faced issue. 

Could you please try refreshing the visual tree before clicking the button? Alternatively you might need to include an execution delay to allow the application to be up and running and fully loaded once the actions starts. Please find below the code samples for these suggestions. 

// Refresh the DOM tree
Manager.ActiveApplication.MainWindow.RefreshVisualTrees();
// Pause the execution for certain amount of time (in ms)
System.Threading.Thread.Sleep(5000);

Please let me know if any of these suggestions works for you. Thanks in advance for your cooperation! 

Regards,
Elena Tsvetkova
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
Alex
Top achievements
Rank 1
answered on 04 Sep 2018, 05:06 PM

Hi Elena,

 

Thanks for the reply. Unfortunately adding the two lines you suggested did not seem to have any impact.

 

Do you have any other ideas I might try? Thanks.

0
Nikolai
Telerik team
answered on 07 Sep 2018, 12:00 PM
Hi Alex,

The code below should be in reversed order: 

// Pause the execution for certain amount of time (in ms)
System.Threading.Thread.Sleep(5000);
 
// Refresh the DOM tree
Manager.ActiveApplication.MainWindow.RefreshVisualTrees();

First wait for 5 sec. so the app. is done rendering and then refresh the visual trees so the testing framework is update. 
If this does not work can you please try to find the element by a different find logic or with a simple "parent to children" recursive function. I suspect that the "AutomationId" might not be properly populated in your case. 


Regards,
Nikolai
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Alex
Top achievements
Rank 1
Answers by
Elena
Telerik team
Alex
Top achievements
Rank 1
Nikolai
Telerik team
Share this question
or