【发布时间】:2014-04-01 22:02:54
【问题描述】:
我在一个页面上有许多 HTMLDIV,我正在尝试使用
UIElement.getProperty("InnerText")
问题是我永远不知道 DIV 将有多少个子元素以及元素将向下多少层。所以我认为递归将适用于这种情况,而不是嵌套的 FOREACH 语句。但是,由于我的 DIVS 没有填充 .NAME 属性并且.GetType 始终是“HTMLDIV”,我不知道如何访问子元素的.Innertext。我打算使用这种方法:
ControlTypeIWantToFind result =
FindVisualChild<ControlTypeIWantToFind>(myPropertyInspectorView);
public static T FindVisualChild<T>(DependencyObject depObj, string strMyInnerText) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
return (T)child;
}
T childItem = FindVisualChild<T>(child);
if (childItem != null) return childItem;
}
}
return null;
}
但我想我需要这样的东西:
if (child != null && child.innerText == strMyInnerText)
我希望一切都有意义。
【问题讨论】:
标签: c# coded-ui-tests