Mitesh
Mitesh

Reputation: 378

mimic 'Enter' Key press in Webtest using Selenium

I want to mimic Enter being pressed in Webtest. I am using Selenium 2.3.1. I want to do it using WebDriver. I know that we can do this using Selenium RC, but I do not want to do it that way. Has anybody done this before? I am open to upgrade to Selenium 2.20.0 (latest).

Upvotes: 4

Views: 4304

Answers (1)

Petr Janeček
Petr Janeček

Reputation: 38424

You can send an Enter key to an element. However, you can't press Enter to, say, confirm a download dialog.

WebElement elem = driver.findElement(By.id("damnit")); // obtain an element
elem.sendKeys(org.openqa.selenium.Keys.ENTER); // this sends an Enter key to the element
elem.sendKeys("hey" + org.openqa.selenium.Keys.ENTER); // this writes and then confirms by Enter

Upvotes: 5

Related Questions