Appium WinAppDriver How to Update the Text in a RichTextBox

How do I send a Non-Printing character, eg Ctrl-A, Delete, Backspace, to a Windows 11 control (eg a Richtextbox in my case).

I have found that

  1. driver.SendKeys() does not clear a Richtextbox before sending the text to the control (like it does for a ‘normal’ Textbox).
  2. driver.Clear() does not clear a RichTextBox (like it does for a ‘normal’ TextBox).
  3. driver.SendKeys() takes a string but if you add a non-printing character to the string, eg ‘\u0008’ (Backspace), it gets ignored

Is there anyway that I can get Appium/WinAppDriver to delete the contents of a Windows control ?

Platform Windows
Appium Version 4.4.0
Language C#
OS - Windows 11
Dell LapTop

Also, these are possible alternatives:


Thanks for the above reply.

I tested the sending of control character to a ‘normal’ Winform Textbox and they worked admirably, however when I tried them on a RichTextBox they failed to work. They ‘flashed’ the text in RTB but did nothing.

Has anyone any idea on how to overwrite the text in a RichTextBox ? It’s a different beast from the normal TextBox.

Afaik RTB should allow to programatically select a text range (SelectionStart/SelectionLength props)

I have found that one cannot use .SendKeys to overwrite the contents of a RichTextBox (as one can with a Textbox).

In order to overwrite the contents of a RichTextBox, you have to do the following:-

  1. Select the control
  2. Select the text in the control
  3. Delete the text
    4.Use SendKeys to copy the desired Text into the control

Here’s the code I used:-

var X = .driver.FindElementByAccessibilityId( "....Id....." );
X.Click();
X.SendKeys(OpenQA.Selenium.Keys.Control + "a" + OpenQA.Selenium.Keys.Control);
X.SendKeys(OpenQA.Selenium.Keys.Delete);
X.SendKeys("... text..." );

Many thanks for your help with this MyKola

1 Like

A quick solution can be like

  1. Get length of text from rich text box
  2. Run a for loop & each iteration send BACK_SPACE keys via sendkeys() method

Sample code :

int backSpaceLen;
backSpaceLen = el.getAttribute(“value”).length();
for (int i = 0; i <= backSpaceLen; i++) {
el.sendKeys(Keys.BACK_SPACE);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}