+10 votes
2 views
by (900 points)
recategorized by

I want to put value using webdriver,

This is the command I am using

driver.findElement(By.name("name")).sendKeys("daniel");

I want to put tab keys and keys in text box, can someone suggest an easy way to do so ?

5 Answers

+6 votes
by (13.2k points)
selected by
 
Best answer

If you want to send keys to a text box and send tab key both at the same time instead of writing two different statements, use a comma.

driver.findElement(By.name("name")).sendKeys("daniel",Keys.TAB);

By using a comma you can send both username and key-stroke at the same time.

If you wish to Learn Selenium visit this Selenium Training by Intellipaat.

by (29.8k points)
thanks this works
by (44.6k points)
Using Keys.TAB helped!
by (47.2k points)
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 the click will do it hopefully.
by (38.2k points)
Thanks a lot. It worked.
+4 votes
by (63.4k points)

If your application is using frames, you can try as follows:

First, pass driver control to the frame using----

driver.switchTo().frame("passid/name/index/webelement";

After that perform the operation which you want to do on the web element present inside frame say here you want to enter the text "daniel"--

driver.findElement(By.name("name")).sendKeys("daniel");

I hope that helps!

by (19.8k points)
It worked for me! Thanks!
by (33.2k points)
Thanks for this clear explanation!
+4 votes
by (31.4k points)

In order to use TAB keys here, you need to do something like below:

Actions builder = new Actions(driver);

builder.keyDown(Keys.TAB).perform()

by (16.3k points)
It worked for me. Thank you.
+1 vote
by (92.8k points)

I also had that problem as well before. But then what I did to make it work is:

myInputElm.click();

myInputElm.clear();

myInputElm.sendKeys('myString');

by (28.1k points)
This worked for me.
0 votes
by (107k points)

You can use click() method [ i.e in your case : clear(), click(), sendKeys() ] before sendkeys()and sendkeys will start working:-

driver.findElement(By.name("name")).clear(); driver.findElement(By.name("name")).click(); driver.findElement(By.name("name")).sendKeys("abc");

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...