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; } }
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); }
/// <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"); } }
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)); } }
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; }
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; } } }
public DataGridInfoPage(System.Windows.Automation.AutomationElement AEControl) { InitializeComponent(); this.AEControl = AEControl; ShowGridData(); ShowDetails(); }
public static IEnumerable<AutomationElement> GetAll(AutomationElement window, string prefix = null) { var res = window.FindAllChildrenByControlType(ControlType.Text); if (prefix != null) res = res.Where(l => l.Current.AutomationId.StartsWith(prefix)); return res; }
/// <summary> /// Constructor for <see cref="BaseActionHandler"/> class. /// </summary> /// <param name="ae">Injected element</param> protected BaseActionHandler(AutomationElement ae) { this.ae = ae; this.identifier = (ae.Current.AutomationId == null) ? ae.Current.Name : ae.Current.AutomationId; }
public UIItem(AutomationElement automationElement, ActionListener actionListener) { if (null == automationElement) throw new NullReferenceException(); this.automationElement = automationElement; this.actionListener = actionListener; factory = new PrimaryUIItemFactory(new AutomationElementFinder(automationElement)); }
protected override int? GetMessagesCount(AutomationElement ae) { string name = ae.Current.Name; if (!name.Contains(base._browserSet.MessengerCaption)) return null; return ae.Current.Name.ParseNumber(); }
// 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); }
void MarkedOp(AutoElem elem, bool ForceRefresh = false) { Console.WriteLine("Op" + (Oper.Operate(elem) ? "Suces" : "Fail")); Nav.VerifySibList(ForceRefresh); ClearMarks(); MarkElemInfo(elem); }
void DrawElemBound(AutoElem ae, Graphics g, Color ForeColor, string Text) { if (ae == null || !ae.Available()) { return; } Rect BudRc = ae.Current.BoundingRectangle; if (BudRc == Rect.Empty) { return; } var ClientRc = this.RectangleToClient(BudRc.ToRectangle()); var ForeBrush = new SolidBrush(ForeColor); var ForePen = new Pen(ForeBrush, 3); var BackBrush = new SolidBrush(ForeColor.RevColor()); var BackPen = new Pen(BackBrush, 5); g.DrawRectangle(BackPen, ClientRc); g.DrawRectangle(ForePen, ClientRc); if (Text != "" && Text != null) { GraphicsPath gp = new GraphicsPath(); gp.AddString(Text, this.Font.FontFamily, (int)Font.Style, Font.Size, new Point(ClientRc.Left, ClientRc.Top), StringFormat.GenericDefault); var ogp = (GraphicsPath)gp.Clone(); gp.Widen(BackPen); g.FillPath(BackBrush, gp); g.FillPath(ForeBrush, ogp); } }
void MarkElemInfo(AutoElem e) { Graphics ImgGraph = Graphics.FromImage(new Bitmap(this.Width, this.Height)); IntPtr ImgHdc = ImgGraph.GetHdc(); Graphics g = Graphics.FromHdc(ImgHdc); g.Clear(Color.Transparent); if (Nav.CondMode) { var t = Nav.CondSibLst.List; DrawElemsBounds(t, g, Color.Black); DrawElemBound(e, g, Color.Gold, null); } else { DrawElemBound(e, g, Color.Black, $"↓{Nav.CurChildCnt} ↔{Nav.CurSibCnt}"); } Graphics FormGraph = Graphics.FromHwnd(this.Handle); IntPtr WinHdc = FormGraph.GetHdc(); BLENDFUNCTION blend = new BLENDFUNCTION(255); Point p = new Point(0, 0); Size s = new Size(Width, Height); UpdateLayeredWindow(this.Handle, WinHdc, IntPtr.Zero, ref s, ImgHdc, ref p, 0, ref blend, 2); }
public void MyTestInitialize() { // Create the factory and register schemas _nFactory = new CUIAutomationClass(); // Start the app var curDir = Environment.CurrentDirectory; _app = new TargetApp(curDir + "\\WpfAppWithAdvTextControl.exe"); _app.Start(); // Find the main control var appElement = _nFactory.ElementFromHandle(_app.MainWindow); var advTestBoxCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "advTextBox1"); _nAdvancedTextBoxElement = appElement.FindFirst(NTreeScope.TreeScope_Children, advTestBoxCondition); Assert.IsNotNull(_nAdvancedTextBoxElement); var testControlCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "testControl"); _nTestControlElement = appElement.FindFirst(NTreeScope.TreeScope_Children, testControlCondition); Assert.IsNotNull(_nTestControlElement); var window = AutomationElement.RootElement.FindFirst(WTreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow")); _wAdvancedTextBoxElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "advTextBox1")); _wTestControlElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "testControl")); }
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; } }
public static bool Click(AutomationElement element) { try { if (AutomationElement.IsInvokePatternAvailableProperty.In(element)) { element.As<InvokePattern>(InvokePattern.Pattern).Invoke(); } else if (AutomationElement.IsTogglePatternAvailableProperty.In(element)) { element.AsTogglePattern().Toggle(); } else if (AutomationElement.IsSelectionItemPatternAvailableProperty.In(element)) { element.AsSelectionItem().Select(); } return true; } catch (Exception e) { Console.WriteLine(e); return false; } }
internal ElementItem(AutomationElement element) { if (element == null) throw new ArgumentNullException(nameof(element)); _element = element; }
/// <summary> /// 指定したName属性に一致するエディットテキスト要素を全て返します /// </summary> /// <param name="rootElement"></param> /// <param name="name"></param> /// <returns></returns> private static IEnumerable<AutomationElement> FindEditByName(AutomationElement rootElement, string name) { const string EDIT_CLASS_NAME = "Edit"; return from x in FindElementsByName(rootElement, name) where x.Current.ClassName == EDIT_CLASS_NAME select x; }
// 指定したName属性に一致するボタン要素をすべて返します private static IEnumerable<AutomationElement> FindButtonsByName(AutomationElement rootElement, string name) { const string BUTTON_CLASS_NAME = "Button"; return from x in FindElementsByName(rootElement, name) where x.Current.ClassName == BUTTON_CLASS_NAME select x; }
// 指定したName属性に一致するAutomationElementをすべて返します private static IEnumerable<AutomationElement> FindElementsByName(AutomationElement rootElement, string name) { return rootElement.FindAll( TreeScope.Element | TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, name)) .Cast<AutomationElement>(); }
public static AutomationElement GetAddInRibbonTabElement(AutomationElement excelElement, ExcelAppWrapper app) { const string TheAddInTabControlName = "The AddIn"; var ribbonTabs = UIAUtility.FindElementByNameWithTimeout(excelElement, "Ribbon Tabs", AddinTestUtility.RibbonButtonsBecomeActivatedTimeout, TreeScope.Descendants); var deTab = UIAUtility.FindElementByNameWithTimeout(ribbonTabs, TheAddInTabControlName, TimeSpan.FromSeconds(5), TreeScope.Descendants); //Note Descendants needed here only for excel 2007 if (app.IsVersion2010OrAbove()) { UIAUtility.SelectMenu(deTab); } else { UIAUtility.PressButton(deTab); } var lowerRibbon = UIAUtility.FindElementByNameWithTimeout(excelElement, "Lower Ribbon", AddinTestUtility.RibbonButtonsBecomeActivatedTimeout, TreeScope.Descendants); return UIAUtility.FindElementByNameWithTimeout(lowerRibbon, TheAddInTabControlName, AddinTestUtility.RibbonButtonsBecomeActivatedTimeout, TreeScope.Descendants); //Note Descendants needed here only for excel 2007 }
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; } } }
public Marker() { InitializeComponent(); SetWindowLong(this.Handle, -20, GetWindowLong(this.Handle, -20) | 0x20 | 0x80000 | 0x08000000); //TRANSPARENT,LAYERED,NOACTIVATE Rectangle ScrBnd = Screen.PrimaryScreen.Bounds; Location = new Point(ScrBnd.Right, ScrBnd.Bottom); Size = ScrBnd.Size; ClearMarks(); Location = new Point(0, 0); Nav = new CountedNavi( AutoElem.FromHandle(GetDesktopWindow()) ); Nav.Walker = TreeWalker.ControlViewWalker; Nav.CurElemChanged += MarkElemInfo; RegHotkey(0, MK.Alt | MK.Control, Keys.Up); RegHotkey(1, MK.Alt | MK.Control, Keys.Down); RegHotkey(2, MK.Alt | MK.Control, Keys.Left); RegHotkey(3, MK.Alt | MK.Control, Keys.Right); RegHotkey(6, MK.Alt | MK.Control, Keys.D1); RegHotkey(7, MK.Alt | MK.Control, Keys.D2); RegHotkey(5, MK.Alt | MK.Control, Keys.Enter); }
/// <summary> /// Get a new IElement from a base AutomationElement. /// </summary> /// <param name="ae">Base AutomationElement</param> /// <returns>An implementation of IElement.</returns> internal static IElement GetIElementFromBase(AutomationElement ae) { return GetIElementFromHandlers( Factories.ElementActionHandlerFactory.GetActionHandler(ae), Factories.ElementDescendantHandlerFactory.GetDescendantHandler(ae) ); }
public static void Enqueue( AutomationElement elementToHighlight, int highlightersGeneration, string highlighterData) { Highlighter highlighter = null; if (null != (elementToHighlight as AutomationElement)) { if (0 >= highlightersGeneration) { HighlighterNumber++; } else { HighlighterNumber = highlightersGeneration; } highlighter = new Highlighter( elementToHighlight.Current.BoundingRectangle.Height, elementToHighlight.Current.BoundingRectangle.Width, elementToHighlight.Current.BoundingRectangle.X, elementToHighlight.Current.BoundingRectangle.Y, elementToHighlight.Current.NativeWindowHandle, (Highlighters)(HighlighterNumber % 10), HighlighterNumber, highlighterData); ExecutionPlan.Enqueue(highlighter); } }
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);*/ }
public int AddUIElement(AutomationElement element) { int id = this.uiElements.Count; this.uiElements.Add(element); logger.Debug("UI element ({0})) added.", id); return id; }
public ScrollBars(AutomationElement automationElement, ActionListener actionListener, ScrollBarButtonAutomationIds hScrollBarButtonAutomationIds, ScrollBarButtonAutomationIds vScrollBarButtonAutomationIds) { this.actionListener = actionListener; this.hScrollBarButtonAutomationIds = hScrollBarButtonAutomationIds; this.vScrollBarButtonAutomationIds = vScrollBarButtonAutomationIds; finder = new AutomationElementFinder(automationElement); }
public SilverlightDocument(AutomationElement automationElement, BrowserWindow actionListener, InitializeOption initializeOption, WindowSession windowSession) : base(automationElement, actionListener, initializeOption, windowSession) { ieWindow = actionListener; }
internal BasePattern( AutomationElement el, SafePatternHandle hPattern ) { Debug.Assert(el != null); _el = el; _hPattern = hPattern; }
protected ScrollBar(AutomationElement automationElement, ActionListener actionListener, ScrollBarButtonAutomationIds automationIds) : base(automationElement, actionListener) { this.automationIds = automationIds; var finder = new AutomationElementFinder(automationElement); primaryUIItemFactory = new PrimaryUIItemFactory(finder); }
/// <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); } }
public UIA2BasicAutomationElement(UIA2Automation automation, UIA.AutomationElement nativeElement) : base(automation) { Automation = automation; NativeElement = nativeElement; PatternFactory = new UIA2PatternFactory(this); Cached = new UIA2AutomationElementInformation(this, true); Current = new UIA2AutomationElementInformation(this, false); }
// TOOD: need to be OO and generic can pass ElementInfo public TableActionsPage(AutomationElement AE) { AEControl = AE; LoadGridToArray(); LoadColumnNameCombo(); mRowCount = rowCount; InitializeComponent(); SetComponents(); }
public ActTableEditPage(AutomationElement AE) { AEControl = AE; calculateGridDimensions(); LoadGridToArray(); LoadColumnNameCombo(); mRowCount = rowCount; InitializeComponent(); SetComponents(); }
protected override void WndProc(ref Message m) { if (m.Msg == 0x0312) //WM_HOTKEY { switch (m.WParam.ToInt32()) { case 0: case 1: case 2: case 3: var t = Nav.NavElem((NavCode)m.WParam); if (t != null) { Console.WriteLine(t); } break; case 5: if (Nav.CondMode) { MarkedOp(Nav.CurElem); } else { Nav.Walker = new TreeWalker(Oper.PropCond); int v = Nav.CondSibLst.Count; Console.WriteLine("Set Walker " + (v > 0 ? "Succeed" : "Failed")); if (v > 0) { if (v == 1 || (Oper.Mode == OpMode.Focus && v < 5)) { MarkedOp(Nav.CurElem); Nav.NavElem(NavCode.Parent); } else { ShowInput(); } } } break; case 6: Nav.CurElem = AutoElem.FromHandle(GetForegroundWindow()); Nav.NavElem(NavCode.Child); break; case 7: ShowInput(); break; } } base.WndProc(ref m); }
protected void VerifyCurElem() { if (!_curElem.Available()) { _curElem = AutoElem.FromHandle(GetDesktopWindow()); Console.WriteLine("Desktop Fallback"); if (CondMode) { Walker = UncondWalker; } } }
public static bool Focus(AutoElem e) { if ((bool)e.GetCurrentPropertyValue(AutoElem.IsKeyboardFocusableProperty)) { e.SetFocus(); Console.WriteLine("UIA SetFocused"); return(true); } else { Console.WriteLine("Not UIA KbdFocusable"); } IntPtr ElemHwnd = new IntPtr(e.Current.NativeWindowHandle); if (IntPtr.Zero.Equals(ElemHwnd)) { Console.WriteLine("ElemHwnd Fail"); return(false); } int CurThd = GetCurrentThreadId(); if (CurThd == 0) { Console.WriteLine("GetCurThd Fail"); return(false); } int ElemThd = GetWindowThreadProcessId(ElemHwnd, out _); if (ElemThd == 0) { Console.WriteLine("GetElemThd Fail"); return(false); } if (!AttachThreadInput(CurThd, ElemThd, true)) { Console.WriteLine("Attach Fail"); AttachThreadInput(CurThd, ElemThd, false); return(false); } GetActiveWindow(); Console.WriteLine(GetFocus()); int v2 = SetFocus(ElemHwnd); Console.WriteLine($"{v2}"); AttachThreadInput(CurThd, ElemThd, false); return(v2 != 0); }
public static bool SelectOne(AutoElem e) { if (e.TryGetCurrentPattern(SelectionItemPattern.Pattern, out object obj)) { var Pattern = obj as SelectionItemPattern; Pattern.Select(); return(true); } else { return(false); } }
public static bool Toggle(AutoElem e) { if (e.TryGetCurrentPattern(TogglePattern.Pattern, out object obj)) { var Pattern = obj as TogglePattern; Pattern.Toggle(); Console.WriteLine("toggled"); return(true); } else { return(Expand(e)); } }
public static bool Invoke(AutoElem e) { if (e.TryGetCurrentPattern(InvokePattern.Pattern, out object obj)) { InvokePattern Pattern = obj as InvokePattern; Pattern.Invoke(); Console.WriteLine("invoked"); return(true); } else { return(false); } }
public static bool ScrollTo(AutoElem e) { if (e.TryGetCurrentPattern(ScrollItemPattern.Pattern, out object obj)) { ScrollItemPattern Pattern = obj as ScrollItemPattern; Pattern.ScrollIntoView(); Console.WriteLine("scrolled to"); return(true); } else { return(false); } }
public static bool Dock(AutoElem e, DockPosition Pos) { if (e.TryGetCurrentPattern(DockPattern.Pattern, out object obj)) { var Pattern = obj as DockPattern; Pattern.SetDockPosition(Pos); Console.WriteLine("docked"); return(true); } else { return(false); } }
public static System.Windows.Automation.AutomationElement GetAutomationElementFromPoint() { System.Windows.Automation.AutomationElement result = null; try { //element = result = AutomationElement.FromPoint(new System.Windows.Point( Cursor.Position.X, Cursor.Position.Y)); //result = element; } catch { } return(result); }
public void CompareAutomationElementsTest() { Process p = BaseTest.StartApplication(@"SampleForm.exe", String.Empty); try { Thread.Sleep(1000); SWA.AutomationElement testFormElement = SWA.AutomationElement.RootElement.FindFirst(SWA.TreeScope.Children, new SWA.PropertyCondition(AEIds.ProcessIdProperty, p.Id)); Assert.IsNotNull(testFormElement, "window"); SWA.AutomationElement groupBox1Element = testFormElement.FindFirst(SWA.TreeScope.Children, new SWA.PropertyCondition(AEIds.ControlTypeProperty, SWA.ControlType.Group)); Assert.IsNotNull(groupBox1Element, "groupBox1"); Assert.IsTrue(SWA.Automation.Compare(testFormElement, testFormElement), "Identity"); SWA.AutomationElement testFormElement2 = SWA.AutomationElement.RootElement.FindFirst(SWA.TreeScope.Children, new SWA.PropertyCondition(AEIds.ProcessIdProperty, p.Id)); Assert.IsTrue(SWA.Automation.Compare(testFormElement, testFormElement2), "Comparing different instances representing the same element"); Assert.IsFalse(SWA.Automation.Compare(testFormElement, groupBox1Element), "Comparing different elements"); bool argumentNullRaised = false; try { SWA.Automation.Compare(testFormElement, null); } catch (ArgumentNullException) { argumentNullRaised = true; } Assert.IsTrue(argumentNullRaised, "Expected ArgumentNullException"); } finally { p.Kill(); } }
static public object GetPropertyGridValue(Core.UIItems.WindowItems.Window mainWindow, string Name) { Panel propertyView = mainWindow.Get <Panel>(SearchCriteria.ByAutomationId("propertyGrid")); Assert.IsNotNull(propertyView); System.Windows.Automation.AutomationElement elem = propertyView.GetElement(SearchCriteria.ByControlType(System.Windows.Automation.ControlType.Table)); Assert.IsNotNull(elem); Core.UIItems.TableItems.Table table = new Core.UIItems.TableItems.Table(elem, new Core.UIItems.Actions.ProcessActionListener(elem)); Assert.IsNotNull(table); System.Windows.Automation.AutomationElement row = table.GetElement(SearchCriteria.ByText(Name)); Assert.IsNotNull(row); object obj = row.GetCurrentPropertyValue(ValuePattern.ValueProperty); Assert.IsNotNull(obj); return(obj); }
public static bool Select(AutoElem e) { if (e.TryGetCurrentPattern(SelectionItemPattern.Pattern, out object obj)) { var Pattern = obj as SelectionItemPattern; if (Pattern.Current.IsSelected) { Pattern.RemoveFromSelection(); } else { Pattern.AddToSelection(); } return(true); } else { return(false); } }
public void DoOperations() { Process[] p = Process.GetProcessesByName("pcsws"); //System.Windows.Automation.AutomationElement t = WinFormAdapter.GetAEFromHandle(p[0].MainWindowHandle); System.Windows.Automation.AutomationElement _0 = AutomationElement.FromHandle(p[0].MainWindowHandle); //System.Windows.Automation.AutomationElement t1 = WinFormAdapter.GetAEOnChildByName(t, "Sesión A - [24 x 80]"); //System.Windows.Automation.AutomationElement t1 = t.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Inicio de sesión de IBM i")); //TODO: Obtener por tipo de elemento (Tipo.Edit) //Al tener el mismo nombre tanto el label como el textbox de un campo, toma los dos, al parecer el segundo siempre es el textbox.... System.Windows.Automation.AutomationElementCollection _0_Descendants_1 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "ID de usuario:")); WinFormAdapter.SetText(_0_Descendants_1[1], "BFPJUARUI"); System.Windows.Automation.AutomationElementCollection _0_Descendants_2 = _0.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Contraseña:")); WinFormAdapter.SetText(_0_Descendants_2[1], "BFPJUARUI2"); WinFormAdapter.ClickElement(WinFormAdapter.GetAEOnDescByName(_0, "Aceptar")); }
static void Main(string[] args) { foreach (var proc in Process.GetProcessesByName("chrome")) { if (proc.MainWindowHandle == IntPtr.Zero) { continue; } var element = AE.FromHandle(proc.MainWindowHandle); //var cond = new PC(AE.NameProperty, "アドレス検索バー")); var cond = new PC(AE.ControlTypeProperty, CT.Edit); var edit = element.FindFirst(TS.Descendants, cond); if (edit == null) { continue; } var pat = edit.GetCurrentPattern(VP.Pattern) as VP; var url = pat.Current.Value as string; // the url value is just surface of edit control, e.g. "http://" is hidden Console.WriteLine(url); } }
/*private static void OpElem(AutoElem e) { * * /*var Center = ((Rect)last.GetCurrentPropertyValue( * AutomationElement.BoundingRectangleProperty)).Center(); * Console.WriteLine(Center); * SetCursorPos(Center); * LeftClick(Center); LeftClick(Center); * foreach (var i in e.GetSupportedPatterns()) { * Console.WriteLine($"{i.Id}: {i.ProgrammaticName}"); * } * }*/ public static bool Auto(AutoElem e) { if ((bool)e.GetCurrentPropertyValue(AutoElem.IsOffscreenProperty)) { if (ScrollTo(e)) { return(true); } } if (Toggle(e)) { return(true); } if (Select(e)) { return(true); } if (Invoke(e)) { return(true); } return(false); }
public static bool ScrollPercent(AutoElem e, double Percent, bool HScroll = false) { if (e.TryGetCurrentPattern(ScrollPattern.Pattern, out object obj)) { var Pattern = obj as ScrollPattern; if (HScroll) { Pattern.SetScrollPercent(Percent, -1); Console.WriteLine("Hpercented"); } else { Pattern.SetScrollPercent(-1, Percent); Console.WriteLine("Vpercented"); } return(true); } else { return(false); } }
public static bool Scroll(AutoElem e, ScrollAmount Amount, bool HScroll = false) { if (e.TryGetCurrentPattern(ScrollPattern.Pattern, out object obj)) { var Pattern = obj as ScrollPattern; if (HScroll) { Pattern.ScrollHorizontal(Amount); Console.WriteLine("Hscrolled"); } else { Pattern.ScrollVertical(Amount); Console.WriteLine("Vscrolled"); } return(true); } else { return(false); } }
public static bool Expand(AutoElem e) { if (e.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out object obj)) { var Pattern = obj as ExpandCollapsePattern; var state = Pattern.Current.ExpandCollapseState; if (ExpandCollapseState.Collapsed == state || ExpandCollapseState.PartiallyExpanded == state) { Pattern.Expand(); Console.WriteLine("expanded"); } else if (ExpandCollapseState.Expanded == state) { Pattern.Collapse(); Console.WriteLine("collapsed"); } return(true); } else { return(false); } }
public static AutomationElement NativeToManaged(UIA2Automation automation, UIA.AutomationElement nativeElement) { return(automation.WrapNativeElement(nativeElement)); }
public UIA2BasicAutomationElement WrapNativeElement(UIA.AutomationElement nativeElement) { return(new UIA2BasicAutomationElement(this, nativeElement)); }
/// <summary> /// Create a new wrapper for the specified element /// </summary> /// <param name="element">The element to wrap in a new automation helper</param> /// <returns>A new automation helper instance wrapping the specified element</returns> protected override ExpandableElement CreateInstance(System.Windows.Automation.AutomationElement element) { return(new ExpandableElement(element)); }
public UIA2FrameworkAutomationElement(UIA2Automation automation, UIA.AutomationElement nativeElement) : base(automation) { Automation = automation; NativeElement = nativeElement; }
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; }); }