I need to automate a Winform application. How do I set the AutomationID
(or AutomationName
) like the the XAML in this article does?
From this stack overflow article the answer seems to be no, unless I switch the application to a WPF application (so I can use XAML to define the controls).
I have tried this na?ve approach:
AutomationElement formAutomation = AutomationElement.FromHandle(this.Handle);
formAutomation.Current.Name = "SandboxResponseDialogName";
formAutomation.Current.ClassName = "SandboxResponseDialogClassName";
formAutomation.Current.AutomationId = "SandboxResponseDialogID;
But at this point in the constructor for the control, these Automation properties have getters only; no setters.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…