The solution is to override the built-in UIAutomation locator functionality (used when testing WPF/Silverlight applications) and modify the locator on the fly. The following simple example will change the location of a checkbox in the sample application to be a different position:
function Test()
{
//Specify the customized locator behavior
overrideLocators();
SeS('CheckBox').DoClick();
}
g_load_libraries=["UIAutomation"];
function overrideLocators()
{
UIAutomationLocator.fromLocationDef = UIAutomationLocator.fromLocation;
UIAutomationLocator.fromLocation=function(objLocation, objInfo)
{
// Do something here if needed
if (objInfo.location == 'tabControl1/tabItem1/checkBoxX')
{
objInfo.location = 'tabControl1/tabItem1/checkBox1';
}
// and/or call default locator
return UIAutomationLocator.fromLocationDef(objLocation, objInfo);
}
}