Press Enter Key in WebDriver

21,959 views
Skip to first unread message

Elango van

unread,
Jan 31, 2013, 5:26:57 AM1/31/13
to webd...@googlegroups.com
Hi,

    I want to click ENTER button in webdriver. I used two ways.

    First:
             driver.findElement(By.id("idValue")).sendKeys(Keys.ENTER);

    Second:
    Actions action = new Actions(driver); 
   action.sendKeys(Keys.ENTER).build().perform();

     But now both are not working for me. So anyone know another idea to click ENTER button ?

pratika

unread,
Jan 31, 2013, 5:29:44 AM1/31/13
to webd...@googlegroups.com
Hi Elango

Why don't you use .click to simulate with the enter button 

Simon Stewart

unread,
Jan 31, 2013, 5:31:34 AM1/31/13
to webd...@googlegroups.com
Dumb question: do you mean the key on the right side of the main part of the keyboard, or the tall vertical one on the number pad? The former is Keys.RETURN, the latter is Keys.ENTER. I only ask because I've seen even experienced developers get the two mixed up to no end of confusion.

You can also use "\n" in your string as a synonym for Keys.RETURN.

Regards,

Simon

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Piyush Dubey

unread,
Apr 23, 2014, 1:04:26 PM4/23/14
to webd...@googlegroups.com
Hi Simon,

I too have a button on a page which is of a "type" submit. 

I'm testing the Accessibility feature of the page and was trying to perform all actions on the page using keyboard.

I need to click on the button. below is the code m using:

pressKey(page, Keys.RETURN);

or

pressKey(page, Keys.ENTER);


/**
* @param page
* @param enter
*/
public void pressKey(WebPage rPage, Keys ...keys) {
 Actions action = new Actions(rPage.getDriver());
 for(Keys key : keys){
 action.sendKeys(key);
}
 action.build();
 Action selectMultiple = action.build();
 selectMultiple.perform();
}



Both the approaches are not working. Can you please help. event sendkeys("\n") didn't work

here's the Html:

<input id="but_Default Button Id" name="" value="Continue" type="submit">

Shailesh Saini

unread,
May 14, 2014, 8:38:38 AM5/14/14
to webd...@googlegroups.com
Use Robot class:

Robot robot = new Robot();
robot.keypress(KeyEvent.VK_ENT);
for alt 
robot.keypress(KeyEvent.VK_ALT);
for key s
robot.keypress(KeyEvent.VK_S);

and many more keys and different keys combination of keyboard.

Hope it will help u.

Thanks,
Shailesh

Piyush Dubey

unread,
May 14, 2014, 11:34:46 AM5/14/14
to webd...@googlegroups.com
Thanks Shailesh,

Let me give it a try.


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.

darrell

unread,
May 15, 2014, 7:46:48 AM5/15/14
to webd...@googlegroups.com
Everyone should remember that using Java's Robot class to control the keyboard will not work with RemoteWebDriver and any remote browsers. So the moment you start using Robot you have thrown away using things like Selenium Grid.

Shailesh Saini

unread,
May 15, 2014, 8:38:01 AM5/15/14
to webd...@googlegroups.com
Thanks Darrell,

I have not worked with selenium Grid. I will definitely remember your valuable suggestion. 

Thanks!!
Reply all
Reply to author
Forward
0 new messages