References: http://blogs.msdn.com/b/mathew_aniyan/archive/2009/12/10/content-index-for-coded-ui-test.aspx
- Using Javascript Execution object ExecuteScript(string script, params object[] args)
Example 1: Search controls by ID
BrowserWindow browserWindow = BrowserWindow.Launch(http://www.amazon.com);
HtmlEdit searchBox = (HtmlEdit) browserWindow.ExecuteScript("return document.getElementById(arguments[0])", "twotabsearchtextbox");
searchBox.Text = "Visual Studio 2012";
Example 2: Take control as argument
BrowserWindow window = BrowserWindow.Launch("http://www.bing.com");
window.ExecuteScript("arguments[0].value = 'CodedUITest'", this.UIMap.UIBingWindowsInternetEWindow.UIBingDocument.UIEnteryoursearchtermCustom);
Example 3: Can return a list<object>, and each object can be typed by the users based on the expectation of return value;
List<object> listOfObjects = (List<object>) browserWindow.ExecuteScript(@" var array = new Array();
array[0] = 'string';
array[1] = 20;
array[2] = document.getElementById('textbox1');
array[3] = new Array();
array[3][0] = 25.34;
array[3][1] = 'string2';
return array; ");
Example 4: Return custom attributes
BrowserWindow browserWindow = BrowserWindow.Launch("http://www.amazon.com");
// <div id="nav_subcats_5" class="nav_browse_subcat nav_super_cat" data-nav-promo-id="digital-games-software" .....
string promoId = (string)browserWindow.ExecuteScript("return document.getElementById('nav_subcats_5').getAttribute('data-nav-promo-id');");
-
Update "search property" and "filter property" for controls
1. May need delete some property in search property. 2. May need move "filter property" to "search property"