Empty Textbox Validation

Ask general questions here.
Thet Thet
Posts: 12
Joined: Fri Jan 11, 2019 7:02 am

Empty Textbox Validation

Post by Thet Thet » Fri Feb 15, 2019 3:49 am

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4421
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Empty Textbox Validation

Post by odklizec » Fri Feb 15, 2019 9:01 am

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Thet Thet
Posts: 12
Joined: Fri Jan 11, 2019 7:02 am

Re: Empty Textbox Validation

Post by Thet Thet » Mon Feb 18, 2019 8:03 am

Hi odklizec ,

It works. :)
Thanks you so much.