本文整理汇总了C#中System.Windows.Automation.AutomationElement.GetCurrentPattern方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.GetCurrentPattern方法的具体用法?C# AutomationElement.GetCurrentPattern怎么用?C# AutomationElement.GetCurrentPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.AutomationElement
的用法示例。
在下文中一共展示了AutomationElement.GetCurrentPattern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
}
示例2: ScrollItemPatternWrapper
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
internal ScrollItemPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
:
base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
{
Comment("Creating ScrollItemTests");
_pattern = (ScrollItemPattern)GetPattern(m_le, m_useCurrent, ScrollItemPattern.Pattern);
if (_pattern == null)
ThrowMe(CheckType.IncorrectElementConfiguration, Helpers.PatternNotSupported + ": ScrollItemPattern");
// Find the ScrollPattern
_container = m_le;
while (_container != null && !(bool)_container.GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty))
_container = TreeWalker.ControlViewWalker.GetParent(_container);
// Check to see if we actual found the container of the scrollitem
if (_container == null)
ThrowMe(CheckType.IncorrectElementConfiguration, "Element does not have a container with ScrollPattern");
Comment("Found scroll container: " + Library.GetUISpyLook(_container));
_scrollPattern = (ScrollPattern)_container.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;
}
示例3: MultipleViewTests
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
public MultipleViewTests(AutomationElement element, TestPriorities priority, string dirResults, bool testEvents, TypeOfControl typeOfControl, IApplicationCommands commands)
:
base(element, TestSuite, priority, typeOfControl, TypeOfPattern.MultipleView, dirResults, testEvents, commands)
{
m_pattern = (MultipleViewPattern)element.GetCurrentPattern(MultipleViewPattern.Pattern);
if (m_pattern == null)
throw new Exception(Helpers.PatternNotSupported);
}
示例4: TogglePatternWrapper
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
protected TogglePatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
:
base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
{
_pattern = (TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern);
if (_pattern == null)
throw new Exception("TogglePattern: " + Helpers.PatternNotSupported);
}
示例5: Check
public static void Check(AutomationElement element)
{
// element.SetFocus();
//SendKeys.SendWait(" ");
TogglePattern togglePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
togglePattern.Toggle();
}
示例6: GetDataGridContent
/// <summary>
/// Gets the content of the AutomationElement of control type DataGrid.
/// </summary>
/// <param name="dataGrid">A data grid control.</param>
/// <returns>A data table containing the contents of the passed data grid.</returns>
public static DataTable GetDataGridContent(AutomationElement dataGrid, string tableName = "DataGrid")
{
if (dataGrid.Current.ControlType != ControlType.DataGrid)
{
throw new Exception("Invalid control type passed to GetDataGridContent.");
}
try
{
GridPattern gp = (GridPattern)dataGrid.GetCurrentPattern(GridPattern.Pattern);
TablePattern tp = (TablePattern)dataGrid.GetCurrentPattern(TablePattern.Pattern);
AutomationElement[] headers = tp.Current.GetColumnHeaders();
DataTable dt = new DataTable(tableName);
foreach (AutomationElement columnHeader in headers)
{
dt.Columns.Add(columnHeader.Current.Name, typeof(String));
}
int colCount = gp.Current.ColumnCount;
int rowCount = gp.Current.RowCount;
for (int r = 0; r < rowCount; r++)
{
DataRow dr = dt.NewRow();
for (int c = 0; c < colCount; c++)
{
dr[c] = gp.GetItem(r, c).Current.Name;
}
dt.Rows.Add(dr);
}
return dt;
}
catch (Exception ex)
{
Log.Write(ex);
return new DataTable();
}
}
示例7: GetText
public static string GetText(AutomationElement element)
{
string content = string.Empty;
TextPattern txtPattern = element.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (txtPattern != null)
{
content = txtPattern.DocumentRange.GetText(-1);
}
return content;
}
示例8: EmptyTextFromChild
private void EmptyTextFromChild(AutomationElement element)
{
if (element.GetSupportedPatterns().Contains(ValuePattern.Pattern))
{
((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).SetValue(string.Empty);
}
else if (element.GetSupportedPatterns().Contains(TextPattern.Pattern))
{
TextPatternRange document =
((TextPattern)Element.GetCurrentPattern(TextPattern.Pattern)).DocumentRange;
AutomationElement[] children = document.GetChildren();
foreach (var child in children)
{
EmptyTextFromChild(child);
}
}
}
示例9: SelectionItemPatternWrapper
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
internal SelectionItemPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
:
base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
{
_pattern = (SelectionItemPattern)GetPattern(m_le, m_useCurrent, SelectionItemPattern.Pattern);
if (_pattern == null)
throw new Exception(Helpers.PatternNotSupported + ": SelectionItemPattern");
_selectionContainer = _pattern.Current.SelectionContainer;
if (_selectionContainer != null)
{
_selectionPattern = _selectionContainer.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern;
if (_selectionPattern == null)
throw new ArgumentException("Could not find the SelectionContainer's SelectionPattern");
}
}
示例10: ExplorerHost
public ExplorerHost()
{
// Start up Explorer and find it
System.Diagnostics.Process.Start("cmd.exe", "/c start %SystemDrive%\\windows\\system32");
// Wait briefly
System.Threading.Thread.Sleep(2000 /* ms */);
// Find it
_element = AutomationElement.RootElement.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.NameProperty, "system32"));
if (_element == null)
{
throw new InvalidOperationException();
}
_hwnd = _element.Current.NativeWindowHandle;
_windowPattern = (WindowPattern)_element.GetCurrentPattern(WindowPattern.Pattern);
}
示例11: GetWindowPattern
private static WindowPattern GetWindowPattern(AutomationElement targetControl)
{
WindowPattern windowPattern = null;
try
{
windowPattern = targetControl.GetCurrentPattern(WindowPattern.Pattern)
as WindowPattern;
}
catch (InvalidOperationException)
{
// object doesn't support the WindowPattern control pattern
return null;
}
// Make sure the element is usable.
if (false == windowPattern.WaitForInputIdle(10000))
{
// Object not responding in a timely manner
return null;
}
return windowPattern;
}
示例12: GetComboBoxContent
/// <summary>
/// Gets the first selected content of the AutomationElement of control type ComboBox.
/// </summary>
/// <param name="comboBoxControl">A combobox control.</param>
/// <returns>Only the first selected item in text format.</returns>
public static string GetComboBoxContent(AutomationElement comboBoxControl)
{
if (comboBoxControl.Current.ControlType != ControlType.ComboBox)
{
throw new Exception("Invalid control type passed to GetRadioButtonCheckState.");
}
try
{
SelectionPattern sp = (SelectionPattern)comboBoxControl.GetCurrentPattern(SelectionPattern.Pattern);
AutomationElement[] selected = sp.Current.GetSelection();
if (selected.Length > 0)
{
return selected[0].Current.Name;
}
return String.Empty;
}
catch (Exception ex)
{
Log.Write(ex);
return String.Empty;
}
}
示例13: Select
protected void Select(AutomationElement element)
{
SelectionItemPattern select = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);
select.Select();
}
示例14: Click
protected void Click(AutomationElement element)
{
var click = element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
click.Invoke();
}
示例15: GetPatternObject
/// -------------------------------------------------------------------
/// <summary>HELPER: Obtains the pattern object and returns true or false depending on success</summary>
/// -------------------------------------------------------------------
private static bool GetPatternObject(AutomationElement element, AutomationPattern automationPattern, ref object patternObj)
{
bool succeeded = true;
try
{
patternObj = element.GetCurrentPattern(automationPattern);
}
catch (InvalidOperationException exception)
{
Dump(exception.ToString(), true, element);
succeeded = false;
}
return succeeded;
}