Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'sendKeys' are not working in Selenium WebDriver

I am not able to put any value in my application using WebDriver. My application is using frames.

I am able to clear the value of my textbox with driver.findElement(By.name("name")).clear();, but I'm unable to put any value using driver.findElement(By.name("name")).sendKeys("manish");. The click command works for another button on the same page.

like image 484
user3162976 Avatar asked Jan 05 '14 17:01

user3162976


People also ask

Why sendKeys is not working in Selenium?

sendKeys() not working in Selenium WebdriverSelenium can run JavaScript commands with the help of the executeScript method. JavaScript command to be used is passed as a parameter to this method. To input text we shall first identify the edit field with the JavaScript method document. getElementsByClassName.

What can I use instead of sendKeys in Selenium?

New Selenium IDE We can input text in the text box without the method sendKeys with thehelp of the JavaScript Executor. Selenium executes JavaScript commands with the help of the executeScript method.

How does sendKeys work in Selenium?

sendkeys() is a method in Selenium that allows QAs to type content automatically into an editable field while executing any tests for forms. These fields are web elements that can be identified using locators like element id, name, class name, etc.


4 Answers

I also had that problem, but then I made it work by:

myInputElm.click();
myInputElm.clear();
myInputElm.sendKeys('myString');
like image 153
andyssundaypink Avatar answered Oct 08 '22 21:10

andyssundaypink


Before sendkeys(), use the click() method (i.e., in your case: clear(), click(), and sendKeys()):

driver.findElement(By.name("name")).clear();
driver.findElement(By.name("name")).click(); // Keep this click statement even if you are using click before clear.
driver.findElement(By.name("name")).sendKeys("manish");
like image 31
sathish p Avatar answered Oct 08 '22 22:10

sathish p


Try clicking on the textbox before you send keys.

It may be that you need to trigger an event on the field before input and hopefully the click will do it.

like image 3
Robbie Wareham Avatar answered Oct 08 '22 22:10

Robbie Wareham


I experienced the same issue and was able to collect the following solution for this:

  1. Make sure element is in focus → try to click it first and enter a string.
  2. If there is some animation for this input box, apply some wait, not static. you may wait for an element which comes after the animation. (My case)
  3. You can try it out using Actions class.
like image 2
Abhinav Saxena Avatar answered Oct 08 '22 21:10

Abhinav Saxena