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:
The code I am using is:
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.
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].
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).
sendkeys()methods are not working then use following two ways to input text:
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");
The second solution worked well for me when even sending keys via a Robot object would not.
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
This should work to insert values/text into Text-box input field. If not working pls cross-check below points:
- Screen/Page is loaded completely
- 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.