Answered by:
Dynamically pass in automationID to at runtime?

Question
-
Hi, so lets say I have a list box that during runtime populates with contents. The automation id’s of these contents are generated during runtime, so if there happens to be 4 items then they would have “Item0”, “Item1”, “Item2”, “Item3” as the automation ID’s.
I’m wondering is there a way to write a method so that I can pass in an int as a parameter and my test will grab the corresponding “Item[int]” cautomationID control? Ie, I don’t want to hardcode individual method’s for grabbing each control since these controls are dynamically generated during runtime.
Thanks
-justin
Friday, November 5, 2010 11:13 PM
Answers
-
Hi,
How about this
public void ClickFolderItem(int index) { WpfListItem item = new WpfListItem(uiListBox); item.SearchProperties.Add(WpfListItem.PropertyNames.AutomationId, index.ToString(), PropertyExpressionOperator.Contains); item.Find();
Mouse.Click(item); }
Thanks & Regards Siddhartha- Proposed as answer by Siddhartha Pandey - MSFTMicrosoft employee, Moderator Tuesday, November 9, 2010 4:48 AM
- Marked as answer by Mathew Aniyan MSFTModerator Friday, May 20, 2011 2:41 AM
Tuesday, November 9, 2010 4:47 AMModerator
All replies
-
Hi,
Listbox.Items gives you the listitem inside the listbox. In your example it looks like the index is sequential (0, 1 …..). Hence listbox.Items[index] will give you what you need.
If that is not the case or you don’t like the performance of items you can use this method
public WpfListItem GetListItem(WpfList listBox, int index) { if (listBox == null) { throw new ArgumentNullException(); } WpfListItem item = new WpfListItem(listBox); item.SearchProperties.Add(WpfListItem.PropertyNames.AutomationId, index.ToString(), PropertyExpressionOperator.Contains); item.Find(); return item; }
Thanks
Siddhartha
- Proposed as answer by Siddhartha Pandey - MSFTMicrosoft employee, Moderator Saturday, November 6, 2010 9:19 AM
Saturday, November 6, 2010 9:19 AMModerator -
I'm not sure i understand the answer. Let me try phrasing another way. Basically i need a way to pass in search criteria at runtime.
For example, I want to have a UI library. I can easily write a method to do something like enter an address into the toolbar:
public void EnterToolbarAddress(string address){
this.UIMap.EnterToolbarAddressParams.UIAddressBar_ComboBoxComboBoxEditableItem = address;
this.UIMap.EnterToolbarAddress();
}
but now i want to create a method, lets say
ClickFolderItem(int i), where i is the number of the folderitem to click. So in code that is using this library i can call "ClickFolderItem(3)" to click on the 3rd item in the list.
How do i pass the parameter from the method call into the search criteria?
Monday, November 8, 2010 6:39 PM -
Hi,
How about this
public void ClickFolderItem(int index) { WpfListItem item = new WpfListItem(uiListBox); item.SearchProperties.Add(WpfListItem.PropertyNames.AutomationId, index.ToString(), PropertyExpressionOperator.Contains); item.Find();
Mouse.Click(item); }
Thanks & Regards Siddhartha- Proposed as answer by Siddhartha Pandey - MSFTMicrosoft employee, Moderator Tuesday, November 9, 2010 4:48 AM
- Marked as answer by Mathew Aniyan MSFTModerator Friday, May 20, 2011 2:41 AM
Tuesday, November 9, 2010 4:47 AMModerator