public IUIAutomationElement GetScrollingContainerElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement frameElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "mainContent"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListControlTypeId); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement contentElement = frameElement.FindFirst(TreeScope.TreeScope_Children, conditions); conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Scrolling Container"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "group"); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement scrollingContainerElement = contentElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(scrollingContainerElement); }
internal static Condition Wrap(IUIAutomationCondition obj) { if (obj is IUIAutomationBoolCondition) { return(new BoolCondition((IUIAutomationBoolCondition)obj)); } else if (obj is IUIAutomationAndCondition) { return(new AndCondition((IUIAutomationAndCondition)obj)); } else if (obj is IUIAutomationOrCondition) { return(new OrCondition((IUIAutomationOrCondition)obj)); } else if (obj is IUIAutomationNotCondition) { return(new NotCondition((IUIAutomationNotCondition)obj)); } else if (obj is IUIAutomationPropertyCondition) { return(new PropertyCondition((IUIAutomationPropertyCondition)obj)); } else { throw new ArgumentException("obj"); } }
public IUIAutomationElement GetBoxFromPane(IUIAutomationElement rootElement, int controlType) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[1]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, controlType); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions); return(reportElement); }
public IUIAutomationElement GetRowOfTabs(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_TabControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "tab"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions); return(reportElement); }
public IUIAutomationElement GetElementFromPane(IUIAutomationElement rootElement, string title) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, title); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_TextControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Descendants, conditions); return(reportElement); }
internal static IUIAutomationCondition[] GetIUIAutomationConditions( Condition[] conditions) { var automationConditionArray = new IUIAutomationCondition[conditions.Length]; for (var index = 0; index < conditions.Length; ++index) { automationConditionArray[index] = conditions[index].IUIAutomationCondition; } return(automationConditionArray); }
internal static IUIAutomationCondition[] ConditionArrayManagedToNative( Condition[] conditions) { IUIAutomationCondition[] unwrappedConditions = new IUIAutomationCondition[conditions.Length]; for (int i = 0; i < conditions.Length; ++i) { unwrappedConditions[i] = ConditionManagedToNative(conditions[i]); } return(unwrappedConditions); }
public IUIAutomationElement GetUpdateLinkElement(IUIAutomationElement updateDocumentElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_HyperlinkControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "headerLinkUpdates"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement updateLinkElement = updateDocumentElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(updateLinkElement); }
public IUIAutomationElement GetAppInfoElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement appInfoElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(appInfoElement); }
public IUIAutomationElement GetTopFreeHome(IUIAutomationElement element) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement topFreeElement = element.FindFirst(TreeScope.TreeScope_Subtree, conditions); Console.WriteLine(topFreeElement.CurrentName); return(topFreeElement); }
public IUIAutomationElement GetInstallButtonElement(IUIAutomationElement appInfoElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Install"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpBuyButton"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement installButtonElement = appInfoElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(installButtonElement); }
public IUIAutomationElement GetUpdateDocumentElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "frameHeader"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement updateElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(updateElement); }
public IUIAutomationElement GetReportElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Report this review"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpReportReviewMenu"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(reportElement); }
public void GoBack(IUIAutomationElement updateElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Back"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "backButton"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement backElement = updateElement.FindFirst(TreeScope.TreeScope_Children, conditions); this.ClickElement(backElement); Thread.Sleep(2000); }
public IUIAutomationElement GetRootElement(IntPtr storeHwnd) { //IUIAutomationCacheRequest cacheRequest = automation.CreateCacheRequest(); IUIAutomationElement storeElement = _automation.ElementFromHandle(storeHwnd); //int[] runtimeId = storeElement.GetRuntimeId(); //for (int i = 0; i < runtimeId.Length; i++) //{ // Console.WriteLine(runtimeId[i]); //} IntPtr webPlatformHwnd = NativeMethods.FindWindowEx(storeHwnd, IntPtr.Zero, "Web Platform Embedding", ""); Console.WriteLine(webPlatformHwnd); IntPtr IEServerHwnd = NativeMethods.FindWindowEx(webPlatformHwnd, IntPtr.Zero, "Internet Explorer_Server", ""); Console.WriteLine(IEServerHwnd); // last native window handler IUIAutomationElement IEServerElement = _automation.ElementFromHandle(IEServerHwnd); IUIAutomationCondition condition1 = _automation.CreatePropertyCondition( UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); IUIAutomationCondition condition2 = _automation.CreatePropertyCondition( UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndCondition(condition1, condition2); IUIAutomationElement IEElement = IEServerElement.FindFirst(TreeScope.TreeScope_Children, conditions); String id = IEElement.CurrentFrameworkId; Console.WriteLine(id); condition1 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Store"); condition2 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); conditions = _automation.CreateAndCondition(condition1, condition2); IUIAutomationElement storePaneElement = IEElement.FindFirst(TreeScope.TreeScope_Children, conditions); IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, ""); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement rootElement = storePaneElement.FindFirst(TreeScope.TreeScope_Children, conditions); return(rootElement); }
//public void RefreshScrollingContainer(IntPtr hwnd) //{ //} public IUIAutomationElement[] GetAppsArray(IUIAutomationElement homeElement) { IUIAutomationCondition condition = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId); IUIAutomationElementArray appsList = homeElement.FindAll(TreeScope.TreeScope_Children, condition); Console.WriteLine(appsList.Length); IUIAutomationElement[] appsArray = new IUIAutomationElement[appsList.Length]; for (int i = 0; i < appsList.Length; i++) { appsArray[i] = appsList.GetElement(i); Console.WriteLine(appsArray[i].CurrentAutomationId); } return(appsArray); }
public IUIAutomationElement[] GetTopFreeHomeArray(IUIAutomationElement element) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElementArray topFreeList = element.FindAll(TreeScope.TreeScope_Children, conditions); IUIAutomationElement[] topFreeArray = new IUIAutomationElement[topFreeList.Length]; for (int i = 0; i < topFreeList.Length; i++) { topFreeArray[i] = topFreeList.GetElement(i); } return(topFreeArray); }
/// <summary> /// Get DesktopElements based on Process Id. /// </summary> /// <param name="pid"></param> /// <returns>return null if we fail to get elements by process Id</returns> public static IEnumerable <DesktopElement> ElementsFromProcessId(int pid) { IUIAutomationElement root = null; IEnumerable <DesktopElement> elements = null; IUIAutomationCondition condition = null; IUIAutomationElementArray elementArray = null; try { // check whether process exists first. // if not, it will throw an ArgumentException using (var proc = Process.GetProcessById(pid)) { root = UIAutomation.GetRootElement(); condition = UIAutomation.CreatePropertyCondition(PropertyType.UIA_ProcessIdPropertyId, pid); elementArray = root.FindAll(TreeScope.TreeScope_Children, condition); elements = ElementsFromUIAElements(elementArray); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { // report and let it return null ex.ReportException(); } #pragma warning restore CA1031 // Do not catch general exception types finally { if (root != null) { Marshal.ReleaseComObject(root); } if (condition != null) { Marshal.ReleaseComObject(condition); } if (elementArray != null) { Marshal.ReleaseComObject(elementArray); } } return(elements); }
/// <summary> /// Get DesktopElement based on Process Id. /// </summary> /// <param name="pid"></param> /// <returns>return null if fail to get an element by process Id</returns> public static DesktopElement ElementFromProcessId(int pid) { IUIAutomationElement root = null; DesktopElement element = null; IUIAutomationCondition condition = null; try { // check whether process exist first. // if not, it will throw an ArgumentException using (var proc = Process.GetProcessById(pid)) { root = UIAutomation.GetRootElement(); condition = UIAutomation.CreatePropertyCondition(PropertyType.UIA_ProcessIdPropertyId, pid); var uia = root.FindFirst(TreeScope.TreeScope_Descendants, condition); element = ElementFromUIAElement(uia); } } catch (Exception ex) { // report and let it return null ex.ReportException(); } finally { if (root != null) { Marshal.ReleaseComObject(root); } if (condition != null) { Marshal.ReleaseComObject(condition); } } return(element); }
public virtual extern IUIAutomationTreeWalker IUIAutomation3_CreateTreeWalker( [MarshalAs(unmanagedType: UnmanagedType.Interface), In] IUIAutomationCondition pCondition);
public virtual extern IUIAutomationCondition IUIAutomation3_CreateOrConditionFromNativeArray( [MarshalAs(unmanagedType: UnmanagedType.Interface), In] ref IUIAutomationCondition conditions, [In] int conditionCount);
////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // This function is not used by the sample, but it shows an alternative approach to building up // the cache of hyperlinks. Depending on the action taken by the target app when providing data // to be stored in the cache of results, different approaches taken by the UIA client can have // different performance benefits. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void BuildListOfHyperlinksFromWindowInternalAlternateApproach(bool fSearchLinkChildren) { // If we're already building up a list of links, ignore this request to refresh the list. // (A shipping app might consider queueing this request in order to refresh the list again // once the in-progress refreshing action is complete.) if (_fRefreshInProgress) { return; } _fRefreshInProgress = true; // First build a cache request in the same way as done elsewhere in the sample. // This means that for each element returned following the search, they will // have their name, bounding rect and Invoke pattern cached. IUIAutomationCacheRequest cacheRequest = _automation.CreateCacheRequest(); cacheRequest.AddProperty(_propertyIdName); cacheRequest.AddProperty(_propertyIdBoundingRectangle); cacheRequest.AddPattern(_patternIdInvoke); // At this point elsewhere in the sample, we specified that we only wanted data // for the hyperlink elements (and optionally their children) cached. In this // approach here, we will say that we want data for ALL descendants of the // found elements cached. cacheRequest.TreeScope = TreeScope.TreeScope_Descendants; // Now create a property condition as we've done elsewhere, to say that we're only // interested in elements which are in the Control view and are hyperlinks. IUIAutomationCondition conditionControlView = _automation.ControlViewCondition; IUIAutomationCondition conditionHyperlink = _automation.CreatePropertyCondition(_propertyIdControlType, _controlTypeIdHyperlink); IUIAutomationCondition condition = _automation.CreateAndCondition(conditionControlView, conditionHyperlink); // Now unlike steps we took elsewhere, specify that the cache request should // have an additional filter of the property condition we just created. cacheRequest.TreeFilter = condition; // Elsewhere in the sample, we called FindAllBuildCache(). This returned an array of hyperlink // elements with their data cached, (and optinally their children with cache data too.) This // CacheLinksFromWindow() function takes a different approach. The element that is returned // from the call to BuildUpdatedCache() below is the browser element with some data cached. // But the returned element will have an array of cached child elements, and each of those // elements will by the hyperlinks we need. So the cache request here has specified through // its tree filter that we're only interest in hyperlinks, whereas elsewhere in this sample, // we supplied that condition in the search call we made. How much difference this makes to // the performance of calls depends on the action taken by the target application. // *** Note, using this appoach, we can't also cache data for the direct children of the // hyperlinks as we did elsewhere in the sample. So whether this approach is practical // depends on the needs of the client application. // Note that with a property conditions, it's not possible to request that the set of elements // returned from a search are all elements which have a control type of hyperlink OR whose parent // has a control type of hyperlink. // Get a handle to the window of interest. IntPtr hwnd = Win32.FindWindow(strBrowserWindowClass, null); if (hwnd != IntPtr.Zero) { IUIAutomationElement elementBrowser = _automation.ElementFromHandleBuildCache(hwnd, cacheRequest); if (elementBrowser != null) { _linkItems.Clear(); IUIAutomationElementArray arrayChildren = elementBrowser.GetCachedChildren(); if (arrayChildren != null) { int cElements = arrayChildren.Length; // Process each returned hyperlink element. for (int idxElement = 0; idxElement < cElements; idxElement++) { IUIAutomationElement elementChild = arrayChildren.GetElement(idxElement); // Take the same action elsewhere in the sample to present the hyperlink // in the sample app UI. string strLinkName = GetCachedDataFromElement(elementChild, fSearchLinkChildren); if (strLinkName != null) { strLinkName = strLinkName.Trim(); LinkItem item = new LinkItem(); item.linkName = strLinkName; item.element = elementChild; _linkItems.Add(item); } } // Notify the main UI thread that a list of links is ready for processing. Do not block in this call. _listViewLinks.BeginInvoke(_UIUpdateDelegate, _linkItems); } } } // Allow another refresh to be performed now. _fRefreshInProgress = false; }
public virtual extern IUIAutomationCondition CreateOrCondition( [MarshalAs(unmanagedType: UnmanagedType.Interface), In] IUIAutomationCondition condition1, [MarshalAs(unmanagedType: UnmanagedType.Interface), In] IUIAutomationCondition condition2);
////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // BuildListOfHyperlinksFromElement() // // Retrieve a list of hyperlinks from a UIAutomation element. Notifies the main // UI thread when it's found all the hyperlinks to be added to the app's list of // hyperlinks. // // Runs on the background thread. // ////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void BuildListOfHyperlinksFromElement(IUIAutomationElement elementBrowser, bool fUseCache, bool fSearchLinkChildren) { IUIAutomationCacheRequest cacheRequest = null; // If a cache is used, then for each of the elements returned to us after a search // for elements, specific properties (and patterns), can be cached with the element. // This means that when we access one of the properties later, a cross-proc call // does not have to be made. (But it also means that when such a call is made, we // don't learn whether the original element still exists.) if (fUseCache) { // Create a cache request containing all the properties and patterns // we will need once we've retrieved the hyperlinks. By using this // cache, when can avoid time-consuming cross-process calls when // getting hyperlink properties later. cacheRequest = _automation.CreateCacheRequest(); // We'll need the hyperlink's name and bounding rectangle later. // A full list of Automation element properties can be found at // http://msdn.microsoft.com/en-us/library/ee684017(v=VS.85).aspx. cacheRequest.AddProperty(_propertyIdName); cacheRequest.AddProperty(_propertyIdBoundingRectangle); // The target of the hyperlink might be stored in the Value property of // the hyperlink. The Value property is only avaliable if an element // supports the Value pattern. This sample doesn't use the Value, but // if it did, it would call the following here. // hr = pCacheRequest->AddProperty(UIA_ValueValuePropertyId); // It's ok to attempt to cache a property on a pattern which might not // exist on the cached elements. In that case, the property just won't // be available when we try to retrieve it from the cache later. // Note that calling AddPattern() does not cache the properties // associated with a pattern. The pattern's properties must be // added explicitly to the cache if required. // Cache the Invoke pattern too. This means when we prepare to invoke a link later, // we won't need to make a cross-proc call during that preparation. (A cross-proc // call will occur at the time Invoke() is actually called.) A full list of patterns // can be found at http://msdn.microsoft.com/en-us/library/ee684023(v=VS.85).aspx. cacheRequest.AddPattern(_patternIdInvoke); // The next step is to specify for which elements we want to have the properties, (and // pattern) cached. By default, caching will occur on each element found in the search // below. But we can also request that the data is cached for direct children of the // elements found, or even all the descendants of the elements founds. (A scope of // Parent or Ancestors cannot be used in a cached request.) // So in this sample, if TreeScope_Element is used as the scope here, (which is the // default), then only properties for the found hyperlinks will be cached. The sample // optionally caches the properties for the direct children of the hyperlinks too. // This means that if we find a hyperlink with no name, we can search the hyperlink's // children to see if one of the child elements has a name we can use. (Searching the // children could be done without using the cache, but it would incur the time cost of // making cross-proc calls.) TreeScope scope = TreeScope.TreeScope_Element; if (fSearchLinkChildren) { scope = scope | TreeScope.TreeScope_Children; } cacheRequest.TreeScope = scope; // Note: By default the cache request has a Mode of Full. This means a reference to the // target element is included in the cache, as well as whatever properties and patterns // we specified should be in the cache. With a reference to the target element, we can: // // (i) Retrieve a property later for an element which we didn't request should be in // the cache. Eg we could call get_CurrentHasKeyboardFocus(). // // (ii) We can call a method of a pattern that the element supports. Eg if Full mode was // not used here, we would not be able to call Invoke() on the hyperlink later. // If we specified a Mode of None for the cache request here, then the results only include // cached data, with no connection at all after the call returns to the source elements. If // only data is required, then it would be preference to use a Mode of None, as less work is // required by UIA. (Also, if a reference to the element is returned in the cache and kept // around for a non-trivial time, then it increases the chances that the target process // attempts to free the element, but it can't do so in a clean manner as it would like, // due to the client app here holding a reference to it.) To specify that we want a Mode of // None, we'd make this call here: // cacheRequest.AutomationElementMode = AutomationElementMode.AutomationElementMode_None; } // Now regardless of whether we're using a cache, we need to specify which elements // we're interested in during our search for elements. We do this by building up a // property condition. This property condition tells UIA which properties must be // satisfied by an element for it to be included in the search results. We can // combine a number of properties with AND and OR logic. // We shall first say that we're only interested in elements that exist in the Control view. // By default, a property condition uses the Raw view, which means that every element in the // target browser's UIA tree will be examined. The Control view is a subset of the Raw view, // and only includes elements which present some useful UI. (The Raw view might include // container elements which simply group elements logically together, but the containers // themselves might have no visual representation on the screen.) IUIAutomationCondition conditionControlView = _automation.ControlViewCondition; IUIAutomationCondition conditionHyperlink = _automation.CreatePropertyCondition(_propertyIdControlType, _controlTypeIdHyperlink); // Now combine these two properties such that the search results only contain // elements that are in the Control view AND are hyperlinks. We would get the // same results here if we didn't include the Control view clause, (as hyperlinks // won't exist only in the Raw view), but by specifying that we're only interested // in the Control view, UIA won't bother checking all the elements that only exist // in the Raw view to see if they're hyperlinks. IUIAutomationCondition condition = _automation.CreateAndCondition(conditionControlView, conditionHyperlink); // Now retrieve all the hyperlinks in the browser. We must specify a scope in the Find calls here, // to control how far UIA will go in looking for elements to include in the search results. For // this sample, we must check all descendants of the browser window. // *** Note: use TreeScope_Descendants with care, as depending on what you're searching for, UIA may // have to process potentially thousands of elements. For example, if you only need to find top level // windows on your desktop, you would search for TreeScope_Children of the root of the UIA tree. (The // root element can be found with a call to IUIAutomation::GetRootElement().) // *** Note: If the following searches included searching for elements in the client app's own UI, // then the calls must be made on a background thread. (ie not your main UI thread.) Once event // handlers are used, then it's preferable to have all UIA calls made on a background thread // regardless of whether the app interacts with its own UI. IUIAutomationElementArray elementArray; if (fUseCache) { elementArray = elementBrowser.FindAllBuildCache(TreeScope.TreeScope_Descendants, condition, cacheRequest); } else { elementArray = elementBrowser.FindAll(TreeScope.TreeScope_Descendants, condition); } // Build up a list of items to be passed to the main thread in order for it to // populate the list of hyperlinks shown in the UI. _linkItems.Clear(); if (elementArray != null) { // Find the number of hyperlinks returned by the search. (The number of hyperlinks // found might be zero if the browser window is minimized.) int cLinks = elementArray.Length; // Process each returned hyperlink element. for (int idxLink = 0; idxLink < cLinks; ++idxLink) { IUIAutomationElement elementLink = elementArray.GetElement(idxLink); // Get the name property for the hyperlink element. How we get this depends // on whether we requested that the property should be cached or not. string strLinkName = null; if (fUseCache) { strLinkName = GetCachedDataFromElement(elementLink, fSearchLinkChildren); } else { strLinkName = GetCurrentDataFromElement(elementLink, fSearchLinkChildren); } // If we have non-null name, add the link to the list. (This sample does not check // for names that only contains whitespace.) if (strLinkName != null) { strLinkName = strLinkName.Trim(); LinkItem item = new LinkItem(); item.linkName = strLinkName; item.element = elementLink; _linkItems.Add(item); } } } // Notify the main UI thread that a list of links is ready for processing. Do not block in this call. _listViewLinks.BeginInvoke(_UIUpdateDelegate, _linkItems); }
public IUIAutomationElement GetUpdateDocumentElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "frameHeader"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement updateElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return updateElement; }
public List <DrawItem> execute() { List <DrawItem> items = new List <DrawItem>(); IUIAutomationElement boxToBorder; IUIAutomationElement tmpElement; Stopwatch watch = new Stopwatch(); watch.Reset(); watch.Start(); IntPtr storeHwnd = IntPtr.Zero; foreach (Process proc in Process.GetProcesses()) { if (proc.MainWindowTitle.StartsWith("Simplify3D")) { storeHwnd = proc.MainWindowHandle; } } // IntPtr storeHwnd = NativeMethods.FindWindow ("Qt5QWindowIcon", "Simplify3D (Licensed to ...)"); IntPtr fffSetings = NativeMethods.FindWindow("Qt5QWindowIcon", "FFF settings"); bool exit = false; if (storeHwnd == IntPtr.Zero) { exit = true; } if (storeHwnd != NativeMethods.GetForegroundWindow() && fffSetings != NativeMethods.GetForegroundWindow()) { exit = true; } if (exit) { //Highlighter.BufferList(new List<DrawItem>()); return(items); } IUIAutomationElement windowApp = _automation.ElementFromHandle(storeHwnd); IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[1]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "FFF Settings"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement settingsPanel = windowApp.FindFirst(TreeScope.TreeScope_Children, conditionArray[0]); //can u see ? if (settingsPanel != null) { try { conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Auto-Configure for Material"); boxToBorder = settingsPanel.FindFirst(TreeScope.TreeScope_Descendants, conditionArray[0]); items.Add(new DrawItem(false, boxToBorder.CurrentBoundingRectangle, Color.Orange)); conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Auto-Configure for Print Quality"); boxToBorder = settingsPanel.FindFirst(TreeScope.TreeScope_Descendants, conditionArray[0]); items.Add(new DrawItem(false, boxToBorder.CurrentBoundingRectangle, Color.Blue)); pane = this.GetSettingsMainPane(settingsPanel); var rowElement = GetRowOfTabs(settingsPanel); var columnElement = GetColumnFromTabRow(rowElement, EXTRUDER); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange)); columnElement = GetColumnFromTabRow(rowElement, LAYER); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue)); columnElement = GetColumnFromTabRow(rowElement, ADDITIONS); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue)); columnElement = GetColumnFromTabRow(rowElement, INFILL); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue)); columnElement = GetColumnFromTabRow(rowElement, SUPPORT); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Blue)); columnElement = GetColumnFromTabRow(rowElement, TEMPERATURE); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange)); columnElement = GetColumnFromTabRow(rowElement, COOLING); items.Add(new DrawItem(false, columnElement.CurrentBoundingRectangle, Color.Orange)); if (rowElement.CurrentName == EXTRUDER) { tmpElement = this.GetElementFromPane(pane, "Extrusion Multiplier"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange)); } else if (rowElement.CurrentName == LAYER) { tmpElement = this.GetElementFromPane(pane, "Primary Layer Height"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); tmpElement = this.GetElementFromPane(pane, "Top Solid Layers"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); tmpElement = this.GetElementFromPane(pane, "Bottom Solid Layers"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); } else if (rowElement.CurrentName == ADDITIONS) { tmpElement = this.GetElementFromPane(pane, "Skirt Layers"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); } else if (rowElement.CurrentName == INFILL) { tmpElement = this.GetElementFromPane(pane, "Interior Fill Percentage"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); } else if (rowElement.CurrentName == SUPPORT) { tmpElement = this.GetElementFromPane(pane, "Support Infill Percentage"); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Blue)); } else if (rowElement.CurrentName == TEMPERATURE) { tmpElement = this.GetBoxFromPane(pane, UIA_ControlTypeIds.UIA_ListControlTypeId); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange)); } else if (rowElement.CurrentName == COOLING) { tmpElement = this.GetBoxFromPane(pane, UIA_ControlTypeIds.UIA_TreeControlTypeId); items.Add(new DrawItem(true, tmpElement.CurrentBoundingRectangle, Color.Orange)); } } catch (NullReferenceException) { Console.WriteLine("shit happens"); } watch.Stop(); int timeout = (1000 / 75) - (int)watch.ElapsedMilliseconds; //Thread.Sleep(timeout); } //Highlighter.BufferList(items); return(items); // grab the context from the state }
public IUIAutomationElement GetTopFreeHome(IUIAutomationElement element) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement topFreeElement = element.FindFirst(TreeScope.TreeScope_Subtree, conditions); Console.WriteLine(topFreeElement.CurrentName); return topFreeElement; }
public IUIAutomationElement[] GetTopFreeHomeArray(IUIAutomationElement element) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[2]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Top free"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElementArray topFreeList = element.FindAll(TreeScope.TreeScope_Children, conditions); IUIAutomationElement[] topFreeArray = new IUIAutomationElement[topFreeList.Length]; for (int i = 0; i < topFreeList.Length; i++) { topFreeArray[i] = topFreeList.GetElement(i); } return topFreeArray; }
public IUIAutomationElement GetScrollingContainerElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "document"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement frameElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "mainContent"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListControlTypeId); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement contentElement = frameElement.FindFirst(TreeScope.TreeScope_Children, conditions); conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Scrolling Container"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "group"); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement scrollingContainerElement = contentElement.FindFirst(TreeScope.TreeScope_Children, conditions); return scrollingContainerElement; }
public IUIAutomationElement GetRootElement(IntPtr storeHwnd) { //IUIAutomationCacheRequest cacheRequest = automation.CreateCacheRequest(); IUIAutomationElement storeElement = _automation.ElementFromHandle(storeHwnd); //int[] runtimeId = storeElement.GetRuntimeId(); //for (int i = 0; i < runtimeId.Length; i++) //{ // Console.WriteLine(runtimeId[i]); //} IntPtr webPlatformHwnd = NativeMethods.FindWindowEx(storeHwnd, IntPtr.Zero, "Web Platform Embedding", ""); Console.WriteLine(webPlatformHwnd); IntPtr IEServerHwnd = NativeMethods.FindWindowEx(webPlatformHwnd, IntPtr.Zero, "Internet Explorer_Server", ""); Console.WriteLine(IEServerHwnd); // last native window handler IUIAutomationElement IEServerElement = _automation.ElementFromHandle(IEServerHwnd); IUIAutomationCondition condition1 = _automation.CreatePropertyCondition( UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); IUIAutomationCondition condition2 = _automation.CreatePropertyCondition( UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndCondition(condition1, condition2); IUIAutomationElement IEElement = IEServerElement.FindFirst(TreeScope.TreeScope_Children, conditions); String id = IEElement.CurrentFrameworkId; Console.WriteLine(id); condition1 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Store"); condition2 = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); conditions = _automation.CreateAndCondition(condition1, condition2); IUIAutomationElement storePaneElement = IEElement.FindFirst(TreeScope.TreeScope_Children, conditions); IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_PaneControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, ""); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement rootElement = storePaneElement.FindFirst(TreeScope.TreeScope_Children, conditions); return rootElement; }
public string GetMail() { string strMailContent = ""; // Try to find a Windows Live Mail window for composing and reading e-mails. // Using the Spy tool, the class of the main window can be found. This test // app assumes there's only one Windows Live Mail window of interest. IntPtr hwnd = Win32.FindWindow("ATH_Note", null); if (hwnd != IntPtr.Zero) { // We found a window, so get the UIA element associated with the window. IUIAutomationElement elementMailAppWindow = _automation.ElementFromHandle( hwnd); // Find an element somewhere beneath the main window element in the UIA // tree which represents the main area where the e-mail content is shown. // Using the Inspect SDK tool, we can see that the main e-mail content // is contained within an element whose accessible name is "NoteWindow". // So create a condition such that the FindFirst() call below will only // return an element if its name is "NoteWindow". IUIAutomationCondition conditionNote = _automation.CreatePropertyCondition( _propertyIdName, "NoteWindow"); IUIAutomationElement elementNoteWindow = elementMailAppWindow.FindFirst( TreeScope.TreeScope_Descendants, conditionNote); // As it happens, the actual element that supports the Text Pattern is // somewhere beneath the "NoteWindow" element in the UIA tree. Using // Inspect we can see that there is an element that supports the // Text Pattern. Once we have that element, we can avoid a cross-process // call to access the Text Pattern object by using cache request. IUIAutomationCacheRequest cacheRequest = _automation.CreateCacheRequest(); cacheRequest.AddPattern(_patternIdTextPattern); // Now find the element that supports the Text Pattern. This test app assumes // there’s only one element that can be returned which supports the Text Pattern. bool fTextPatternSupported = true; IUIAutomationCondition conditionTextPattern = _automation.CreatePropertyCondition( _propertyIdIsTextPatternAvailable, fTextPatternSupported); IUIAutomationElement elementMailContent = elementMailAppWindow.FindFirstBuildCache( TreeScope.TreeScope_Descendants, conditionTextPattern, cacheRequest); // Because the Text Pattern object is cached, we don't have to make a cross-process // call here to get object. Later calls which actually use methods and properties // on the Text Pattern object will incur cross-proc calls. IUIAutomationTextPattern textPattern = (IUIAutomationTextPattern) elementMailContent.GetCachedPattern( _patternIdTextPattern); // This test app is only interested in getting all the e-mail text, so we get that through // the DocumentRange property. A more fully featured app might be interested in getting a // collection of Text Ranges from the e-mail. Each range might relate to an individual // word or paragraph. Given that a provider which supports the Text Pattern allows a // client to find the bounding rectangles of these ranges, the client could choose to use // its own method of highlighting the text as the text is being spoken. IUIAutomationTextRange rangeDocument = textPattern.DocumentRange; // Pass -1 here because we're not interested in limiting the amount of text here. strMailContent = rangeDocument.GetText(-1); } return(strMailContent); }
public virtual extern IUIAutomationCondition IUIAutomation3_CreateNotCondition( [MarshalAs(unmanagedType: UnmanagedType.Interface), In] IUIAutomationCondition condition);
public IUIAutomationElement GetUpdateLinkElement(IUIAutomationElement updateDocumentElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_HyperlinkControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "headerLinkUpdates"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement updateLinkElement = updateDocumentElement.FindFirst(TreeScope.TreeScope_Children, conditions); return updateLinkElement; }
public IUIAutomationElement GetReportElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Report this review"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_GroupControlTypeId); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpReportReviewMenu"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement reportElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return reportElement; }
// Step 2: Find all the links of interest on the loaded page. private void buttonFindLinks_Click(object sender, EventArgs e) { checkedListBoxLinks.Items.Clear(); if (webBrowserPage.Url == null) { MessageBox.Show(this, "Please load the web page of interest.", "Link Getter", MessageBoxButtons.OK); labelLinkCount.Text = "No links found."; return; } // Get the UIA element for the webBrowser with the page of interest loaded. IUIAutomationElement elementBrowser = automation.ElementFromHandle(webBrowserPage.Handle); // Build up a cache request for all the data we need, to reduce the time it // takes to access the link data once with have the collection of links. IUIAutomationCacheRequest cacheRequest = automation.CreateCacheRequest(); cacheRequest.AddProperty(propertyIdName); cacheRequest.AddPattern(patternIdValue); cacheRequest.AddProperty(propertyIdValueValue); // Assume the links have names as expected, and we don't need to // search children of the links for names. cacheRequest.TreeScope = TreeScope.TreeScope_Element; // We want the collection of all links on the page. IUIAutomationCondition conditionControlView = automation.ControlViewCondition; IUIAutomationCondition conditionHyperlink = automation.CreatePropertyCondition( propertyIdControlType, controlTypeIdHyperlink); IUIAutomationCondition finalCondition = automation.CreateAndCondition( conditionControlView, conditionHyperlink); // TODO: Call FindAllBuildCache() in a background thread in case it takes // a while. As it is, the app UI's going to freeze. // Now get the collection of links. IUIAutomationElementArray elementArray = elementBrowser.FindAllBuildCache( TreeScope.TreeScope_Descendants, finalCondition, cacheRequest); if (elementArray != null) { // Process each returned hyperlink element. for (int idxLink = 0; idxLink < elementArray.Length; ++idxLink) { IUIAutomationElement elementLink = elementArray.GetElement(idxLink); // Despite the fact that we've got the names of the UIA links, don't // use that information here. Perhaps we will use it in the future. IUIAutomationValuePattern valuePattern = (IUIAutomationValuePattern)elementLink.GetCurrentPattern( patternIdValue); if (valuePattern != null) { // We're only interested in references the page makes to itself. string strValueLink = valuePattern.CachedValue; var index = strValueLink.IndexOf('#'); if ((index > 0) && strValueLink.StartsWith(textBoxURL.Text)) { checkedListBoxLinks.Items.Add(new LinkItem() { linkName = elementLink.CachedName, linkURL = strValueLink }); } } } } // Let's assume we'll want most of the links found. SetLinkCheckedState(true); labelLinkCount.Text = "Count of links found: " + checkedListBoxLinks.Items.Count; }
public IUIAutomationElement FindFirstNative(TreeScope treeScope, IUIAutomationCondition condition) { return(CacheRequest.IsCachingActive ? this.NativeElement.FindFirstBuildCache((Interop.UIAutomationClient.TreeScope)treeScope, condition, CacheRequest.Current.ToNative(this.Automation)) : this.NativeElement.FindFirst((Interop.UIAutomationClient.TreeScope)treeScope, condition)); }
public IUIAutomationElement GetAppInfoElement(IUIAutomationElement rootElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[3]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_DocumentControlTypeId); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "wsFrame"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement appInfoElement = rootElement.FindFirst(TreeScope.TreeScope_Children, conditions); return appInfoElement; }
private static IUIAutomationElement FindAndWait(IUIAutomationElement rootElement, TreeScope scope, IUIAutomationCondition condition, TimeSpan timeout) { var stopwatch = Stopwatch.StartNew(); do { var result = rootElement.FindAll(scope, condition); if (result.Length > 1) { throw new Exception("Found multiple elements"); } else if (result.Length == 1) { return(result.GetElement(0)); } Thread.Sleep(1); } while (stopwatch.Elapsed < timeout); throw new TimeoutException(); }
public IUIAutomationElement GetInstallButtonElement(IUIAutomationElement appInfoElement) { IUIAutomationCondition[] conditionArray = new IUIAutomationCondition[4]; conditionArray[0] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, "Install"); conditionArray[1] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "pdpBuyButton"); conditionArray[2] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_FrameworkIdPropertyId, "InternetExplorer"); conditionArray[3] = _automation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ButtonControlTypeId); IUIAutomationCondition conditions = _automation.CreateAndConditionFromArray(conditionArray); IUIAutomationElement installButtonElement = appInfoElement.FindFirst(TreeScope.TreeScope_Children, conditions); return installButtonElement; }