RichTextBox Automation

May 20, 2009 at 8:02 AM

Could anyone tell me how to automate the wpf Richtextbox control?

May 21, 2009 at 7:59 AM
Edited May 21, 2009 at 7:59 AM

Sorry, I should have tried a bit more before creating the discussion here... I was not clear about the concept of how the Richtextbox works...

This should help the beginners like me .......

To get the richtext box,

PropertyCondition prop = new PropertyCondition(AutomationElement.ClassNameProperty, "RichTextBox");
AutomationElement ae = _app.CurrentWindow.AutomationElement.FindFirst(TreeScope.Descendants, prop);

Check whether the control supports the value pattern or not... If it supports the text pattern then it will not support the value pattern and we need to use send keys to enter the text into the control


// clear the existing content

// enter the new content

System.Windows.Forms.SendKeys.SendWait("UI Automation. Core is amazing stuff....Good support vivek");

// To get the content from the Richtext box

TextPattern ta = ae.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
var content = ta.DocumentRange.GetText(-1);





May 25, 2009 at 10:53 AM

have you tried this:

var textBox = window.Get<MultilineTextBox>("textBox1");

textBox.Text = "foobar";

Apr 8, 2010 at 4:13 PM


I am trying to set text to WPF RichTextBox.   The below code does not seems to work.  I need advice.

            White.Core.UIItems.MultilineTextBox richTextBox = window.Get<White.Core.UIItems.MultilineTextBox>("richTextBox");

            richTextBox.Text = "1231233434";



Apr 9, 2010 at 12:48 PM

I have found out the reason to my problem.  My richTextBox is a child of a WPF UserControl.