TonyH
March 28, 2023, 8:59am
1
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
driver.SendKeys() does not clear a Richtextbox before sending the text to the control (like it does for a ‘normal’ Textbox).
driver.Clear() does not clear a RichTextBox (like it does for a ‘normal’ TextBox).
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:
TonyH
April 4, 2023, 11:54am
4
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)
TonyH
April 5, 2023, 6:58pm
6
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:-
Select the control
Select the text in the control
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
Get length of text from rich text box
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();
}
}