RichTextBox automation support - unable to get text using White'sUI
I am trying to read text from RichTextBox using White UI Automation Utility , but it always returns null.
Already added below code to RichtextBox.cs
protected override AutomationPeer OnCreateAutomationPeer()
{
return new RichTextBoxAutomationPeer(this);
}
Is there a way to bypass the text? or using TextPattern?
+3
source to share
1 answer
I have been using white for a while now, I know this is really late, but I had the same problem. I used the text template to get the value from a rich text box, find the example code below, hope it helps anyway.
AutomationElement ele =window.GetElement(SearchCriteria.ByAutomationId("richTextBoxId>"));
if (ele != null)
{
TextPattern txtPattern = ele.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
String controlText = txtPattern.DocumentRange.GetText(-1);
Debug.WriteLine("the text is" + controlText);
}
+2
source to share