How to validate the input fields in selenium framework?.

559 views
Skip to first unread message

kan...@gmail.com

unread,
Apr 23, 2019, 1:03:22 PM4/23/19
to Selenium Users
I've got a chance to work in automation project. While automation I got stuck in a place where I need to validate my test data before entering it into the fields. I've gone through all the sites but I didn't get the answer which I expected. 

For example: 

Let's say that there is a text field and it accepts upto 100 characters, it's mandatory, etc. And I'm getting input data from excel file. 

My doubt is: 

How to validate the input data in a framework?. Should we have any common methods to validate textbox, radio button, dropdown etc?..

Rakesh Arrepu

unread,
Apr 24, 2019, 2:57:20 AM4/24/19
to Selenium Users
You can use the attribute "maxlength" of input element or similar kind of attribute associated to the element.
Here is the example.

 public void ValidateData()
        {
            WebElement inputEle = Driver.FindElement(By.Id("abc"));
            string val = inputEle.GetAttribute("maxlength");
            int maxLength = Int32.Parse(val);

            //Input Text from excel
            string inputStr = "example test data from excel";
            int textFromExcelLength = inputStr.Length;

            if(textFromExcelLength <= maxLength)
            {
                // perform action
            }
            else
            {
                // throw error
            }
        }

You can try the above and validate the data for input field

poobathy r

unread,
Apr 24, 2019, 11:37:51 AM4/24/19
to seleniu...@googlegroups.com
Please make sure that length of the input property..

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4247d548-9946-408b-ab8a-ee17a3f780b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

poobathy r

unread,
Apr 25, 2019, 7:49:18 AM4/25/19
to seleniu...@googlegroups.com
What kind of input validation are you looking for? If you need general validation..check the property of the textbox by not providing the input..


G

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

LKRG

unread,
Apr 25, 2019, 4:14:15 PM4/25/19
to Selenium Users
Test data that you read from excel file will be assigned to a string, get the length of string and validate the value against the acceptable limit before entering or input in to your text field.
Reply all
Reply to author
Forward
0 new messages