One of the elements in our AUT has changed from a standard text box to a RichTextBox, which is constructed in a completely different way to a standard textbox. Because of this change, I am now really struggling to get the text back to validate against.
The text element now contains the string below and the 50.00 is the text that I am trying to validate against. I have a working RexEx example to get the text back ( <Paragraph>(\d{1,3}(?:\.\d{2})?)<\/Paragraph> ), but the devs say that this will be fragile due to continual changes/updates to .net.
I have hunted around the web for a C# solution and there is limited help for this issue.
One of our devs pointed me at this code, but I have not been able to get it working, as I have been unable to locate which assembly 'TextRange' and 'Document' live under:
Code: Select all
string StringFromRichTextBox(RichTextBox rtb)
{
TextRange textRange = new TextRange(
// TextPointer to the start of content in the RichTextBox.
rtb.Document.ContentStart,
// TextPointer to the end of content in the RichTextBox.
rtb.Document.ContentEnd
);
// The Text property on a TextRange object returns a string
// representing the plain text content of the TextRange.
return textRange.Text;
}
Code: Select all
// Get the RichTextBox control using Ranorex Studio's repository
var richTextBox = repo.MyForm.MyRichTextBox;
// Create a TextAdapter instance for the RichTextBox control
var textAdapter = new TextAdapter(richTextBox);
// Get the text content of the RichTextBox control
var text = textAdapter.GetText();
// Print the text content to the console
Console.WriteLine(text);
Any help or suggestions would be appreciated.
Cheers,
James
Ranorex version: 10.5.4
.net version: 7
Windows 10