I am not able to validate an international number text box in Selenium.

I have tried earlier by name, class and other locators but it is not inserting the value into the textbox.

Below is the text box and the corresponding HTML:

this the textbox

html content

The code I am using is:

  • 1
    What exactly you want to do with these Text boxes? by using any locators you have to enter text in to the textbox or you have to validate these textboxes? May 3, 2016 at 7:34
  • if you see in above image home phone has a format of international number ,now when i try to insert any number using any locator and using sendkeys method it is not accepting the input. May 3, 2016 at 11:38
  • What are you using to drive Selenium, and can you post your code?
    – Cronax
    May 3, 2016 at 13:45
  • driver.findElement(By.name("phone")).sendKeys("(222)222-2222"); driver.findElement(By.id("ssn")).sendKeys("555-55-5555"); May 5, 2016 at 6:55
  • So is it working or not? what's your problem with this? What you expect from us? May 7, 2016 at 6:02

3 Answers 3


If sendkeys() methods are not working then use following two ways to input text:

  1. Before sendkeys() use click() method to click inside textfield i.e:

  2. Second way is to use javascript to input text in texfields like this:

    WebElement wb = driver.findElement(By.name("phone"));
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("arguments[0].value='(222)222-2222';", wb);

Please let me know if that works for you. Webdriver provided the javscript implementation library so that we could use javascript to perform actions on browser which are not possible with with webdriver native API. And in web automation testing services we encountered many such issues where we have to go beyond webdriver native API and have to use javscript methods.

  • 1
    Second solution seems to have better chance of success Mar 13, 2018 at 7:20
  • 1
    The second solution worked well for me when even sending keys via a Robot object would not.
    – Doug Noel
    Aug 1, 2018 at 13:59
  • 1
    The first solution worked for me thank you
    – wallop
    Jul 19, 2019 at 18:24
  • Unfortunately none of the solutions worked for me. From what I understand (as I am working with a credit card number input field) there is some sort of javascript validation that changes some property of the field right when the sendKeys is filling it up. As a result the string always looks incomplete. Jun 20, 2020 at 23:07

First once clear the input text fields and send the input values. Create a reference object for better use:

webElement objPh=driver.findElement(By.name("phone"));   
webElement objSSN=driver.findElement(By.name("ssn"));

objPh.clear();   //To clear the phone text field    
objPh.sendkeys("(222)222-2222"); // To send the input values in phone text field

objSSN.clear(); //To clear the phone ssn text field 
objSSN.sendkeys("555-55-5555"); // To send the input values in ssn text field
  • why clear them? he said he can't input to them so whether he clears them or not wouldn't make a difference to whether or not he can input to them would it? And why do you think he might have been unable to sendkeys to the textboxes?
    – barlop
    Dec 28, 2018 at 15:41

driver.findElement(By.name("Email")).sendKeys("[email protected]");

This should work to insert values/text into Text-box input field. If not working pls cross-check below points:

  1. Screen/Page is loaded completely
  2. Assert that textbox is enabled and visible

If you found any of above points failing, you should try:


This method simple implemented using implicit wait to give additional time to element/text/screen/page to get loaded.

Not the answer you're looking for? Browse other questions tagged or ask your own question.