3

我正在自动化 Windows 应用程序。我试图访问选项卡控件下的窗格元素(具有文本框、组合框控件),但无法访问。白色返回空值。

我尝试了其他技术,如 UI 自动化 TreeWalker(Rawview、控制视图、内容视图),但没有任何帮助。

参考以下链接中的图片: https://dl.dropboxusercontent.com/u/68446125/Tab.png https://dl.dropboxusercontent.com/u/68446125/General%20Pane.png

如图 1 所示,选项卡控件由 White/UI 自动化正确检索,但未返回子元素 General* Pane 且其控件不可访问(请参阅图 2 突出显示),第一个可访问的子元素是“General* tab Item” ”。

奇怪的是,这些控件可以在 Inspect.exe(在 windows SDK 中)中访问。我尝试了以下方法来检索控件,但 General* Pane 永远无法通过 White/UI 自动化访问。

var tab = Window.Get<Tab>(SearchCriteria.ByControlType(ControlType.Tab).AndByClassName("TwoPageControl")); // Tab control is retrieved properly
var pane = tab.GetElement(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*")); // this line returns NULL

var pane1 = revWindow.GetElement(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*")); // this line returns NULL
var pane2 = revWindow.Get<Panel>(SearchCriteria.ByControlType(ControlType.Pane).AndByText("General*"));// throws exception "Failed to get ControlType=pane,Name=General*,ControlType=pane"

也尝试过 Windows UI 自动化代码,但没有运气。

 System.Windows.Automation.Condition cd1 = new AndCondition(
                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Tab),
                new PropertyCondition(AutomationElement.ClassNameProperty, "TwoPageControl"));     

            AutomationElement a = window.FindFirst(TreeScope.Descendants, cd1); // Tab control is returned properly here

          TreeWalker rawViewWalker = TreeWalker.RawViewWalker;
            AutomationElement cc = rawViewWalker.GetFirstChild(a); // General * Pane is not returned, instead General* Tab item is returned, though it's not the first child.
            var cd = rawViewWalker.GetNextSibling(cc);  // this returns next pane element available, not General * Pane.               

请帮助我如何访问 General * Pane 及其在选项卡控制下的子项。任何帮助深表感谢。

4

2 回答 2

1

我的应用程序遇到了完全相同的问题。我使用 Inspect 和开源 UIAVerify,其中 Pane 元素作为选项卡元素的子元素可见。但是当我将验证编译为 .Net 4.5 项目时,窗格元素并未被视为选项卡的一部分。只有当我直接指向它时它才会出现。我还在主窗口的后代中搜索了我的窗格元素,但什么也没有。我认为这与动态创建该窗格内容有关(我的意思是当您选择不同的 tabItem 时会有不同的内容)。

我认为您无法从树的角度访问该元素。

我的解决方案是使用 AutomationElement.FromPoint 方法。 http://msdn.microsoft.com/en-us/library/system.windows.automation.automationelement.frompoint(v=vs.110).aspx

如果您与开发程序的人有联系,我也认为这应该有所帮助。 页面上的某些控件对于 MS UI 自动化不可见

于 2014-11-26T11:54:48.917 回答
0

您可以将 TabControl 分解为仅 TabPanel,但没有其 ContentPresenter。您创建自己的 ContentPresenter,它使用所选 TabItem 的内容。

这样,White 将能够发现 ContentPresenter 中的控件。

这是一种解决方法,很遗憾您不得不更改您的 WPF 代码,因为“UIA 出现问题”。但这是我能做的最好的了。

<Grid>

    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <TabControl x:Name="uiTab" Grid.Row="1">

      <TabControl.Template>
        <ControlTemplate TargetType="TabControl">
          <TabPanel IsItemsHost="True" VerticalAlignment="Stretch"/>
        </ControlTemplate>
      </TabControl.Template>

      <TabItem Header="first">
        <Button>FIRST</Button>
      </TabItem>
      <TabItem Header="second">
        <Button>SECOND</Button>
      </TabItem>

    </TabControl>

    <ContentPresenter Content="{Binding SelectedItem.Content, ElementName=uiTab}"/>

  </Grid>
于 2017-08-10T14:30:53.573 回答