本文整理汇总了C#中System.Windows.Automation.AutomationElement类的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement类的具体用法?C# AutomationElement怎么用?C# AutomationElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AutomationElement类属于System.Windows.Automation命名空间,在下文中一共展示了AutomationElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllChildNodes
public AutomationElementCollection GetAllChildNodes(AutomationElement element, AutomationProperty automationProperty, object value, TreeScope treeScope)
{
var allChildNodes = element.FindAll(treeScope, GetPropertyCondition(automationProperty, value));
if (allChildNodes == null)
throw new ElementNotAvailableException("Not able to find the child nodes of the element");
return allChildNodes;
}
示例2: SilverlightDocument
public SilverlightDocument(AutomationElement automationElement, BrowserWindow actionListener,
InitializeOption initializeOption,
WindowSession windowSession)
: base(automationElement, actionListener, initializeOption, windowSession)
{
ieWindow = actionListener;
}
示例3: executePattern
public void executePattern(AutomationElement subject, AutomationPattern inPattern)
{
switch (inPattern.ProgrammaticName)
{
case "InvokePatternIdentifiers.Pattern":
{
InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
invoke.Invoke();
break;
}
case "SelectionItemPatternIdentifiers.Pattern":
{
SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
select.Select();
break;
}
case "TogglePatternIdentifiers.Pattern":
{
TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
toggle.Toggle();
break;
}
case "ExpandCollapsePatternIdentifiers.Pattern":
{
ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
// exColPat.Expand();
break;
}
}
}
示例4: RunTest
/// <summary>
/// this Method will run automationTests for automationElement
/// </summary>
public static void RunTest(IEnumerable<AutomationTest> automationTests, AutomationElement automationElement, bool TestEvents, IWin32Window parentWindow)
{
using (AutomationTestManager manager = new AutomationTestManager(TestEvents, false))
{
RunTestInternal(automationTests, automationElement, parentWindow, manager);
}
}
示例5: AddUIElement
public int AddUIElement(AutomationElement element)
{
int id = this.uiElements.Count;
this.uiElements.Add(element);
logger.Debug("UI element ({0})) added.", id);
return id;
}
示例6: Test
public void Test(int hwd)
{
var h = FindTradeWindow.Find(new IntPtr(hwd));
if (h < 0) // 说明之前没有启动过
{
Process pro = Process.Start(@"D:\tc_pazq\tc.exe", "");
}
while (window == null)
{
Thread.Sleep(2000);
try
{
if (h > 0)
{
window = AutomationElement.FromHandle(new IntPtr(h));
break;
}
else
{
h = FindTradeWindow.Find(new IntPtr(hwd));
}
}
catch (Exception e)
{
}
}
/*var desktop = AutomationElement.RootElement;
var condition = new PropertyCondition(AutomationElement.NameProperty, "通达信网上交易V6.51 芜湖营业部 周嘉洁"); // 定义我们的查找条件,名字是test
var window = desktop.FindFirst(TreeScope.Children, condition);*/
}
示例7: TestMoveWindow
// CONSIDER: This will run on our automation thread
// Should be OK to call MoveWindow from there - it just posts messages to the window.
void TestMoveWindow(AutomationElement listWindow, int xOffset, int yOffset)
{
var hwndList = (IntPtr)(int)(listWindow.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty));
var listRect = (Rect)listWindow.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
Debug.Print("Moving from {0}, {1}", listRect.X, listRect.Y);
Win32Helper.MoveWindow(hwndList, (int)listRect.X - xOffset, (int)listRect.Y - yOffset, (int)listRect.Width, 2 * (int)listRect.Height, true);
}
示例8: UIItem
public UIItem(AutomationElement automationElement, ActionListener actionListener)
{
if (null == automationElement) throw new NullReferenceException();
this.automationElement = automationElement;
this.actionListener = actionListener;
factory = new PrimaryUIItemFactory(new AutomationElementFinder(automationElement));
}
示例9: InteractiveWindow
public InteractiveWindow(string title, AutomationElement element, VisualStudioApp app)
: base(null, element) {
_app = app;
_title = title;
var compModel = _app.GetService<IComponentModel>(typeof(SComponentModel));
var replWindowProvider = compModel.GetService<InteractiveWindowProvider>();
_replWindow = replWindowProvider
#if DEV14_OR_LATER
.GetReplToolWindows()
#else
.GetReplWindows()
#endif
.OfType<ToolWindowPane>()
.FirstOrDefault(p => p.Caption.Equals(title, StringComparison.CurrentCulture));
#if DEV14_OR_LATER
_interactive = ((IVsInteractiveWindow)_replWindow).InteractiveWindow;
#else
_interactive = (IReplWindow)_replWindow;
#endif
_replWindowInfo = _replWindows.GetValue(_replWindow, window => {
var info = new InteractiveWindowInfo();
_interactive.ReadyForInput += new Action(info.OnReadyForInput);
return info;
});
}
示例10: ButtonClick
private static bool ButtonClick(AutomationElement inElement, string automationId)
{
PropertyCondition btnCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);
Console.WriteLine("Searching for the {0} button...", automationId);
AutomationElement control = inElement.FindFirst(TreeScope.Descendants, btnCondition);
if (control != null)
{
Console.WriteLine("Clicking the {0} button", automationId);
object controlType = control.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty);
if (controlType == ControlType.Button)
{
InvokePattern clickCommand = control.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
clickCommand.Invoke();
}
else if (controlType == ControlType.RadioButton)
{
SelectionItemPattern radioCheck = control.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
radioCheck.Select();
}
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Button {0} clicked.", automationId);
return true;
}
else
{
Console.WriteLine("Could not find button {0} ", automationId);
return false;
}
}
示例11: Matches
private static bool Matches(AutomationElement element, Condition condition) {
// return element.FindFirst(TreeScope.Element, condition) != null; // TODO does this suffer the same bug?
if(condition == Condition.TrueCondition)
return true;
if(condition == Condition.FalseCondition)
return false;
if(condition is NotCondition)
return !Matches(element, ((NotCondition)condition).Condition);
if(condition is AndCondition) {
foreach(Condition c in ((AndCondition)condition).GetConditions())
if(!Matches(element, c))
return false;
return true;
}
if(condition is OrCondition) {
foreach(Condition c in ((OrCondition)condition).GetConditions())
if(Matches(element, c))
return true;
return false;
}
if(condition is PropertyCondition) {
if(!(condition is PropertyCondition2))
throw new Exception("Please use PropertyCondition2 instead of PropertyCondition. PropertyCondition does not properly expose its value.");
PropertyCondition2 pc = (PropertyCondition2)condition;
object actualValue = element.GetCurrentPropertyValue(pc.Property);
object desiredValue = pc.RealValue;
if((pc.Flags & PropertyConditionFlags.IgnoreCase) == PropertyConditionFlags.IgnoreCase &&
(actualValue is string) && (desiredValue is string))
return ((string)actualValue).Equals((string)desiredValue, StringComparison.InvariantCultureIgnoreCase);
return Equals(actualValue,desiredValue);
}
throw new Exception("Unsupported condition type "+condition);
}
示例12: CaptureAutomationElement
private static void CaptureAutomationElement(AutomationElement element, string path, string fileName)
{
Rect elementRect = (Rect)element.Current.BoundingRectangle;
Bitmap dumpBitmap = new Bitmap(
Convert.ToInt32(elementRect.Width),
Convert.ToInt32(elementRect.Height));
using (Graphics targetGraphics = Graphics.FromImage(dumpBitmap))
{
Point captureTopLeft = new Point(
Convert.ToInt32(elementRect.TopLeft.X),
Convert.ToInt32(elementRect.TopLeft.Y));
Size captureSize = new Size(dumpBitmap.Width, dumpBitmap.Height);
targetGraphics.CopyFromScreen(captureTopLeft, new Point(0, 0), captureSize);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
dumpBitmap.Save(string.Format("{0}\\{1}.bmp", path, fileName));
}
}
示例13: ValidateElement
/// <summary>
/// Validates the element.
/// </summary>
/// <param name="element">The element.</param>
protected override void ValidateElement(AutomationElement element)
{
if(!element.Current.IsPassword)
{
throw new IncompatibleElementException("The specified element was found but is not compatible with PasswordBox");
}
}
示例14: AddAutomationPropertyChangedEventHandler
public static void AddAutomationPropertyChangedEventHandler(AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler, params AutomationProperty[] properties)
{
Utility.ValidateArgumentNonNull(element, "element");
Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");
Utility.ValidateArgumentNonNull(properties, "properties");
if (properties.Length == 0)
{
throw new ArgumentException("AtLeastOnePropertyMustBeSpecified");
}
int[] propertyIdArray = new int[properties.Length];
for (int i = 0; i < properties.Length; ++i)
{
Utility.ValidateArgumentNonNull(properties[i], "properties");
propertyIdArray[i] = properties[i].Id;
}
try
{
PropertyEventListener listener = new PropertyEventListener(AutomationElement.StructureChangedEvent, element, eventHandler);
Factory.AddPropertyChangedEventHandler(
element.NativeElement,
(UIAutomationClient.TreeScope)scope,
CacheRequest.CurrentNativeCacheRequest,
listener,
propertyIdArray);
ClientEventList.Add(listener);
}
catch (System.Runtime.InteropServices.COMException e)
{
Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
}
}
示例15: Header
public Header(AutomationElement element) : base(element) {
AutomationElementCollection headerItems = FindAllByControlType(ControlType.HeaderItem);
for (int i = 0; i < headerItems.Count; i++) {
string colName = headerItems[i].GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
if (colName != null && !_columns.ContainsKey(colName)) _columns[colName] = i;
}
}