forked from open-rpa/openrpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsTreeElement.cs
70 lines (66 loc) · 2.56 KB
/
WindowsTreeElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.AutomationElements.Infrastructure;
using FlaUI.Core.Definitions;
using OpenRPA.Interfaces.Selector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenRPA.Windows
{
public class WindowsTreeElement : treeelement
{
private ITreeWalker _treeWalker;
public AutomationElement RawElement { get; set; }
private AutomationBase automation { get; set; }
public ControlType ControlType { get; set; }
public WindowsTreeElement(treeelement parent, bool expanded, AutomationBase automation, AutomationElement element, ITreeWalker treeWalker) : base(parent)
{
Element = new UIElement(element);
_treeWalker = treeWalker;
this.automation = automation;
RawElement = element;
IsExpanded = expanded;
string controltype = "";
string name = "unknown";
string automationid = "";
ControlType = ControlType.Window;
if (element.Properties.ControlType.IsSupported) ControlType = element.Properties.ControlType.Value;
if (element.Properties.ControlType.IsSupported) controltype = element.Properties.ControlType.Value.ToString();
if (element.Properties.Name.IsSupported) name = element.Properties.Name.Value;
if (element.Properties.AutomationId.IsSupported) automationid = element.Properties.AutomationId.Value;
Name = (controltype + " " + name + " " + automationid).Trim();
if (string.IsNullOrEmpty(Name))
{
try
{
var c = element.Properties.ControlType.ValueOrDefault;
controltype = c.ToString();
Name = (controltype + " " + name + " " + automationid).Trim();
}
catch (Exception)
{
throw;
}
}
}
public override void AddSubElements()
{
var elementNode = _treeWalker.GetFirstChild(RawElement);
while (elementNode != null)
{
Children.Add(new WindowsTreeElement(this, false, automation, elementNode, _treeWalker));
try
{
elementNode = _treeWalker.GetNextSibling(elementNode);
}
catch (Exception)
{
elementNode = null;
}
}
}
}
}