4

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).

Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
Mitesh
  • 378
  • 1
  • 6
  • 19

1 Answers1

5

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
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145