ustaw tekst na textfield / textbox za pomocą szkieletu automatyzacji i pobierz zdarzenie zmiany
Chcę ustawić tekst na elemencie textfield / textbox za pomocą MircosoftAutomatyzacja interfejsu użytkownika ramy, to znaczy naAutomationElement
zControlType.Edit
lubControlType.Document
.
W tej chwili używamTextPattern
aby pobrać tekst z jednego z nichAutomationElements
:
TextPattern tp = (TextPattern)element.GetCurrentPattern(TextPattern.Pattern);
string text = tp.DocumentRange.GetText(-1).Trim();
Ale teraz chcę ustawić nowy tekst wAutomationElement
. Nie mogę znaleźć metody na to wTextPattern
klasa. Więc próbuję użyćValuePattern
ale nie jestem pewien, czy to właściwy sposób:
ValuePattern value = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
value.SetValue(insertText);
Czy istnieje inny sposób ustawienia wartości tekstu?
Innym pytaniem jest, jak mogę uzyskać zdarzenie, gdy tekst został zmieniony na aEdit
/ Document
element? Próbowałem użyćTextChangedEvent
ale nie otrzymuję żadnych wydarzeń podczas zmiany tekstu:
AutomationEventHandler ehTextChanged = new AutomationEventHandler(text_event);
Automation.AddAutomationEventHandler(TextPattern.TextChangedEvent, element, TreeScope.Element, ehTextChanged);
private void text_event(object sender, AutomationEventArgs e)
{
Console.WriteLine("Text changed");
}