Reputation: 11
I have an object in a codedui uimap ... let's say it's
UIMap.Browser.Document.Table.Row.Cell
E.g., your code looks like this :
UITestControl testcontrol = this.UIMap.Browser.Document.Table.Row.Cell;
I need to find the object "Cell" as a fully qualified name, given a string "Browser.Document.Table.Row.Cell".
The result must be a UITestControl, so it can then be manipulated by the test.
The idea is, using the string containing the path, find the actual object in the uimap.
I can generate the string containing the "path" to the object, just can't figure out how to then search for it within the uimap, and link that back to a UITestControl.
(This is all from a C# standpoint)
e.g.,
String objectString = "Browser.Document.Table.Row.Cell";
UITestControl newcontrol = nameoffunctionweneed(objectString);
in this case, nameoffunctionweneed
accepts a String, and outputs a UITestControl object.
Upvotes: 1
Views: 401
Reputation: 348
It's better to work with the element directly given that paths can change very often. So, you'd work best with the simple CodedUI approach to searching for elements.
Given:
<html>
<body>
<table>
<tr>
<td id="x1_y1"><span>hello World!</span></td>
</tr>
</table>
</body>
</html>
Find the table cell by:
var cellEle = new HtmlTableCell(browser);
cellEle.SearhProperties[HtmlTableCell.PropertyNames.Id] = "x1_y1";
// OR
cellEle.SearhProperties[HtmlTableCell.PropertyNames.InnerText] = "hello World!";
Upvotes: 0
Reputation: 501
This might solve your problem:
UITestControl nameoffunctionweneed(string path)
{
object res = UIMap;
foreach (var item in path.Split('.'))
{
res = res.GetType().GetProperty(item).GetValue(res, null);
}
return res as UITestControl;
}
Upvotes: 1