c# - Coded UI confused when selecting from list with identical items -
in 1 of application's windows have list box displaying 2 records:
john smith
john smith
these 2 different records. when click hand on first john smith record, i'm supposed see phone number (555-555-5555), , do. when click on second john smith record, i'm supposed see different phone number (777-777-7777), , well.
however, when record clicking on first item in list, same code when clicking on second item in list (codedui looking "john smith" item in list display text , selecting it, instead of selecting item @ whatever list index had clicked). assertions fail when want verify second john smith's phone number (777-777-7777) because codedui selects first record , gets first john smith's number (555-555-5555) instead.
how work around it? need support users have identical names. no, not want add information first "john smith" make display differently second "john smith".
/// <summary> /// inownersrecordswindowselectfirstitem - use 'inownersrecordswindowselectfirstitemparams' pass parameters method. /// </summary> public void inownersrecordswindowselectfirstitem() { #region variable declarations winlist uilistboxownersrecordslist = this.uiownersrecordswindow.uilistboxownersrecordswindow.uilistboxownersrecordslist; #endregion // select 'john smith' in 'listboxownersrecords' list box uilistboxownersrecordslist.selecteditemsasstring = this.inownersrecordswindowselectfirstitemparams.uilistboxownersrecordslistselecteditemsasstring; } /// <summary> /// inownersrecordswindowselectseconditem - use 'inownersrecordswindowselectseconditemparams' pass parameters method. /// </summary> public void inownersrecordswindowselectseconditem() { #region variable declarations winlist uilistboxownersrecordslist = this.uiownersrecordswindow.uilistboxownersrecordswindow.uilistboxownersrecordslist; #endregion // select 'john smith' in 'listboxownersrecords' list box uilistboxownersrecordslist.selecteditemsasstring = this.inownersrecordswindowselectseconditemparams.uilistboxownersrecordslistselecteditemsasstring; } /// <summary> /// parameters passed 'inownersrecordswindowselectfirstitem' /// </summary> [generatedcode("coded uitest builder", "14.0.23107.0")] public class inownersrecordswindowselectfirstitemparams { #region fields /// <summary> /// select 'john smith' in 'listboxownersrecords' list box /// </summary> public string uilistboxownersrecordslistselecteditemsasstring = "john smith"; #endregion } /// <summary> /// parameters passed 'inownersrecordswindowselectseconditem' /// </summary> [generatedcode("coded uitest builder", "14.0.23107.0")] public class inownersrecordswindowselectseconditemparams { #region fields /// <summary> /// select 'john smith' in 'listboxownersrecords' list box /// </summary> public string uilistboxownersrecordslistselecteditemsasstring = "john smith"; #endregion }
there workaround this, need hand-coded. also, if can share code of page list located, easier me help. asking because can use parent-child relations. let’s presume standard html list id.
<ul id=”list”> <li>john smith</li> <li>john smith</li> </ul> you find john smith want parent-child relation.
var parent = findlistbyid(browser, "list"); var child1 = parent.getchildren()[0]; // 1st child of ul id=list, in case first john smith var child2 = parent.getchildren()[1]; // 2nd child of ul id=list, in case second john smith mouse.click(child2); public htmllist findlistbyid(uitestcontrol parent, string id) { var parentlist= new htmllist(parent); parentlist.searchproperties.add(htmllist.propertynames.id, id); return parentlist; } if list spans inside of div or that, logic same. first find parent of controls (id or friendly name best), search children can done on multiple levels.
Comments
Post a Comment