Sometimes, you need to provide test data during run time like, enter inputs through keyboard for further action. what do you do to make UFT accept inputs? well, we will learn in this post.
Input Box
“InputBox Function” displays a prompt in a dialog box, waits for the user to enter text and/ or click a button. To simply define:
Inputbox(): To read user input values or keyboard inputs during runtime.
Syntax :
InputBox("User message","Enter Title","Default Message") or InputBox("User message","Enter Title","Default Message",xpos,ypos,helpfile,context)
The output is a dialogue box shown up, asking the user to enter values, as shown in below examples.
User Message : Its the prompt which displays the user message. for e.g: Enter a 3 digit number.
Enter Title (optional): The title of the input box as shown in the example as ‘Enter Title’.
Default Message (optional) : This message is displayed by default if no other input is provided.
xpos,ypos (optional) : The position of the dialogue box is determined by these positional values.
Help file (optional) : Help file to use to provide context-sensitive Help for the dialog box.
Example 1 :
Dim Input Input = InputBox("Enter your name") MsgBox ("You entered: " & Input)
Output :
Example 2 : Using Enter Title and Default Message.
Dim Input Input = InputBox("User message","Enter Title","Default Message") MsgBox ("You entered: " & Input)
Output:
Example 3: To display user message in multiple lines
Dim Inp Inp= InputBox("Enter"&chr(13)&"first name"&chr(13)&"Gendr"&chr(13)&"AGE") MsgBox ("You entered: " & Inp)
Output:
If user message consists of more than one line, you can separate the lines using a carriage return character (Chr(13)). Msgbox and InputBox are valuable features while scripting, Just learn different ways to use them and you are way to go!