How to overwrite text in a text input field?
How to overwrite text in a text input field?
I want use the Automation API to overwrite the text in a text input field on a web page. Is there a simpler way to do it than clicking in the field and pressing the backspace key repeatedly, then typing the new text?
Re: How to overwrite text in a text input field?
Try this...
Code: Select all
Keyboard.Press("{END}{SHIFT DOWN}{HOME}{SHIFT UP}{DELETE}" + strMyText);
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: How to overwrite text in a text input field?
Worked like a charm. Thanks!
Re: How to overwrite text in a text input field?
This seems like a common enough usage that there should be a method within Ranorex.InputTag, or any type of adapter that deals with textboxes, to do this very thing.
In my case, I find that I'll more often want to overwrite an input box than add characters to the string that's already present.
I wonder what the best practice for adding such functionality to Ranorex adapters would be.
Extension methods? Static methods? Container classes? Inheritance?
I've currently started to add extension methods, so that I can call an input box from a repository (ex: repo.browser.inputbox), and directly use my extensions (ex: inputbox.OverwriteText("test") ), but I'm not sure about how maintainable this solution is vs. the alternatives.
In my case, I find that I'll more often want to overwrite an input box than add characters to the string that's already present.
I wonder what the best practice for adding such functionality to Ranorex adapters would be.
Extension methods? Static methods? Container classes? Inheritance?
I've currently started to add extension methods, so that I can call an input box from a repository (ex: repo.browser.inputbox), and directly use my extensions (ex: inputbox.OverwriteText("test") ), but I'm not sure about how maintainable this solution is vs. the alternatives.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: How to overwrite text in a text input field?
Hello,
things that come up again and again for one tester is most likely different from things that reoccur for other testers. To provide API functions for all the situations would unnecessarily blow up the API. Ranorex API is built on .NET and with C# or VB it is very easy to write a function that can be reused again and again. If built against the 3.5 framework then extension classes are a good fit for such situations:
Roland
Ranorex Support Team
things that come up again and again for one tester is most likely different from things that reoccur for other testers. To provide API functions for all the situations would unnecessarily blow up the API. Ranorex API is built on .NET and with C# or VB it is very easy to write a function that can be reused again and again. If built against the 3.5 framework then extension classes are a good fit for such situations:
public static class adapter_extensions { public static void ClearText(this Ranorex.Adapter a) { a.PressKeys("{END}{SHIFT DOWN}{HOME}{SHIFT UP}{DELETE}"); } } // other code here void ITestModule.Run() { // other code here Ranorex.Text t = "/form[@controlname='formVipApplication']/text/text[@accessiblename='First Name:']"; t.ClearText(); }Regards,
Roland
Ranorex Support Team
Re: How to overwrite text in a text input field?
That's a great example of Extension Methods for this particular example.
I like how it integrates with code completion, acting like the method is simply another one of the (extended) object's public methods.
The only other part to worry about was, like you mentioned, that I had to set the project's "Target Framework" to ".Net Framework 3.5" and add a reference to "System.Core".
Thanks for the response!
I like how it integrates with code completion, acting like the method is simply another one of the (extended) object's public methods.
The only other part to worry about was, like you mentioned, that I had to set the project's "Target Framework" to ".Net Framework 3.5" and add a reference to "System.Core".
Thanks for the response!