426. Entering an integer variables value into a text box field using sendKeys( ) command

Have you ever tried printing an integer value using sendKeys( ). If not, you should know that sendKeys( ) will return an error if you have used the following statement to enter the integer variables value:

_driver.findElement(By.cssSelector("CSS PATH of any Text Field")).sendKeys(IntegerVariable);

So how to solve this problem ?

In order to solve this problem, we have to make a small modification to the above statement by changing sendKeys(IntegerVariable) to sendKeys(" "+IntegerVariable) as shown below:

_driver.findElement(By.cssSelector("CSS PATH of any Text Field")).sendKeys(" "+IntegerVariable);

Test Description:

Now lets print an integer variables value using sendKeys( ) command as explained in the below screenshot:

Lets Implement the Test on Eclipse IDE:


1. Create a new Java Project say 'WebDriver-Project71' in Eclipse IDE
2. Configure the Project to work with Selenium WebDriver
3. Create a package say 'package71' under the newly created project.
4. Create a Java Class file say 'Class71' under the newly created package as shown below:

Actual Steps:

1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:

2. Create a test method 'enterIntegerVariableValueUsingsendKeys()'  as shown below:

3. Declare an integer variable say 'count' and assign it with some value say '99' as shown below:

4. Enter the value of the above declared integer variable  using sendKeys( ) command into a text box field as shown below:

5. Save and Run the '' file by selecting the 'JUnit Test' option and ensure that our Automation Test has enter the value of the integer variable 'count' i.e. 99 into the Username text box field as shown below:

Watch the below video:

Click here to watch the video.

Download this Project:

Click here to download this project and import into Eclipse IDE  on your machine.

Please comment below to feedback or ask questions.

Using size( ) to retrieve the count of list options available in the drop down field   will be explained in the next post.

No comments:

Followers :)

Blog Index