3

UIAutomationを使用して、外部アプリケーションからDatagrid内のすべてのアイテムを取得する必要があります。現在、表示されているアイテムのみを取得(およびUISpyで表示)できます。データグリッド内のすべてのアイテムをキャッシュしてからプルする方法はありますか?コードは次のとおりです。

static public ObservableCollection<Login> GetLogins()
    {

        ObservableCollection<Login> returnLogins = new ObservableCollection<Login>();

        var id = System.Diagnostics.Process.GetProcessesByName("<Name here>")[0].Id;
        var desktop = AutomationElement.RootElement;

        var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id));

        var datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "lv"));

        var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));

        foreach (AutomationElement loginLine in loginLines)
        {
            var loginInstance = new Login { IP = new IP() };

            var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));

            for (var i = 0; i < loginLinesDetails.Count; i++)
            {
                var cacheRequest = new CacheRequest 
                { 
                    AutomationElementMode = AutomationElementMode.None,
                    TreeFilter = Automation.RawViewCondition
                };

                cacheRequest.Add(AutomationElement.NameProperty);
                cacheRequest.Add(AutomationElement.AutomationIdProperty);

                cacheRequest.Push();

                var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));

                cacheRequest.Pop();

                var myString = targetText.Cached.Name;

                #region Determine data and write to return object
                //Removed private information
                #endregion
                }

            }

            returnLogins.Add(loginInstance);
        }

        return returnLogins;
    }
4

2 に答える 2

2

テーブルの仮想化がオンになっているため、表示されているセルのみを取得できます。

仮想化を無効にしてみてください(すべてのアプリケーションで常に可能であるとは限りませんが、テストの前に仮想化を構成に移動して変更したい場合があります)

于 2012-08-27T23:58:04.643 に答える
1

私はこれが不可能であると99%確信しています。UIオートメーションは、グリッドの現在表示されている部分によって表されるデータ構造を認識していません。目に見えるものだけが見えます。すべてのデータを取得するには、グリッドをページングする必要があると思います(これが私が行うことです)。

于 2012-08-29T15:40:08.047 に答える