I am trying to enter text in a edit field in a modal window. I get an error "Failed to get (ControlType=edit or ControlType=document),AutomationId=1118,ClassName=Edit"
The following is my code.
var window = app.GetWindow("Toolkit Version");
Window AuthWindow = null;
AuthWindow = window.ModalWindow("Please Authenticate");
TextBox userNameField = AuthWindow.Get<TextBox>(SearchCriteria.ByClassName("Edit").AndAutomationId("1118"));
userNameField.Text = "Administrator";
From Inspect
Error details -
TestStack.White.AutomationException: 'Failed to get (ControlType=edit or ControlType=document),AutomationId=1118,ClassName=Edit'
Any suggestions or workarounds? Thanks!
Off the top of my head:
Perhaps your SearchCriteria are too restrictive? Try:
TextBox userNameField = AuthWindow.Get<TextBox>(SearchCriteria.ByAutomationId("1118"));
or even
TextBox userNameField = AuthWindow.Get(SearchCriteria.ByAutomationId("1118")) as TextBox;
It might not be very elegant, but it looks like your window is small and has few controls. Why not picking them this way?
TextBox userNameField = AuthWindow.GetMultiple(SearchCriteria.ByControlType(System.Windows.Automation.ControlType.Edit)[0]
I supposed your textbox is at position 0 but of course you can change that.