Page 1 of 1

Empty Textbox Validation

Posted: Fri Feb 15, 2019 3:49 am
by Thet Thet
In my test I need to handle textbox value. Click button If the textbox value is empty. Not Click button If the textbox value is not empty.
How can I do that in my test suite or user code.
Thanks you.

Re: Empty Textbox Validation

Posted: Fri Feb 15, 2019 9:01 am
by odklizec
Hi,

Generally speaking, you will have to write a method, which checks the emptiness of the textbox in question (based of its innertext, value, text or another attribute usually containing validated text) and if empty, perform the click on given button. Unfortunately, without seeing, at very least, Ranorex snapshot (NOT screenshot) of the problematic textbox, it's impossible for us to provide exact code you should use. I can provide with just an example how I would handle such situation. Here is the code...
        /// <summary>
        /// methods check the emptiness of textBoxElement and if empty, click buttonToClick element
        /// </summary>
        /// <param name="textBoxElementInfo"></param>
        /// <param name="buttonToClickInfo"></param>
        public void CheckEmptiness(Ranorex.Core.Repository.RepoItemInfo textBoxElement, Ranorex.Core.Repository.RepoItemInfo buttonToClick)
		{
        	if (textBoxElementInfo.Exists())
        	{
        		string textBoxVal = textBoxElementInfo.CreateAdapter<Ranorex.Unknown>(false).Element.GetAttributeValueText("InnerText")
        		if (string.IsNullOrEmpty(textBoxVal))
        		{
        			buttonToClickInfo.CreateAdapter<Ranorex.Unknown>(false).Click();
        		}
        	}
        }
Where "textBoxElement" and "buttonToClick" should be filled from repository and "InnerText" may be replaced with another attribute (Text, Value, etc...), which usually contains text. Hope this helps?

Re: Empty Textbox Validation

Posted: Mon Feb 18, 2019 8:03 am
by Thet Thet
Hi odklizec ,

It works. :)
Thanks you so much.