Selenium - sendKeys() not inserting value into textbox

  • 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:

    driver.findElement(By.name("phone")).sendKeys("(222)222-2222");   
    driver.findElement(By.id("ssn")).sendKeys("555-55-5555");
    

    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?

    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.

    What are you using to drive Selenium, and can you post your code?

    driver.findElement(By.name("phone")).sendKeys("(222)222-2222"); driver.findElement(By.id("ssn")).sendKeys("555-55-5555");

    So is it working or not? what's your problem with this? What you expect from us?

    By 'what are you using to drive selenium' I mean python/c#/java/ruby/[insert language here].

    i am using Java

    The type for the text box is "text" with a max length of 10. The character input that you're trying to enter is greater than the max length. Did you try entering an input which is less than the max length?

    I have experienced a similar issue with Phone Number fields. I have found that by clearing the field and then sending the keys to correct the issue (as seen in Pavan Kumar's answer).

    facing same problem , sendkeys mehtod not working , i thing control is not reaching there

  • 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:

      driver.findElement(By.name("phone")).click();
      driver.findElement(By.name("phone")).sendKeys("(222)222-2222");   
      driver.findElement(By.id("ssn")).click();
      driver.findElement(By.id("ssn")).sendKeys("555-55-5555"); 
      
    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);
      jse.executeScript("document.getElementById('ssn').value='555-55-5555';");
      

    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.

    Second solution seems to have better chance of success

    The second solution worked well for me when even sending keys via a Robot object would not.

    The first solution worked for me thank you

  • 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?

  • 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:

    WaitForElement(your_element_textbox)
    

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

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM