Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automation support for RichTextBox - Unable to get text using White'sUI

I am trying to read the Text from RichTextBox using White's UI automation framework however it always returns null.

Already added the below code to the RichtextBox.cs

   protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new RichTextBoxAutomationPeer(this);
    }

Is there any workaround to get the text? or by using TextPattern?

like image 582
AProgrammer Avatar asked Mar 19 '26 08:03

AProgrammer


1 Answers

I have been using white for a while now, I know this is really late , but i had the same issue. I have used text pattern to get the value from a rich text box, find the sample code below , hope this helps in 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);

        }
like image 147
Automator1992 Avatar answered Mar 21 '26 23:03

Automator1992



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!