How to overwrite text in a text input field? : Automation API

How to overwrite text in a text input field?

Class library usage, coding and language questions.

How to overwrite text in a text input field?

Postby jstr » Wed Mar 30, 2011 6:24 pm

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?
jstr
 
Posts: 4
Joined: Wed Mar 30, 2011 4:59 pm

Re: How to overwrite text in a text input field?

Postby Ciege » Wed Mar 30, 2011 7:11 pm

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...
User avatar
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: How to overwrite text in a text input field?

Postby jstr » Wed Mar 30, 2011 8:48 pm

Worked like a charm. Thanks!
jstr
 
Posts: 4
Joined: Wed Mar 30, 2011 4:59 pm

Re: How to overwrite text in a text input field?

Postby mrusso » Fri Jun 24, 2011 8:51 pm

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.
mrusso
 
Posts: 16
Joined: Thu Feb 03, 2011 1:54 am

Re: How to overwrite text in a text input field?

Postby Support Team » Mon Jun 27, 2011 2:26 pm

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:
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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: How to overwrite text in a text input field?

Postby mrusso » Mon Jun 27, 2011 7:42 pm

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!
mrusso
 
Posts: 16
Joined: Thu Feb 03, 2011 1:54 am


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests