2012-03-16 107 views
4

我想模仿输入在Webtest中被按下。我正在使用Selenium 2.3.1。我想用WebDriver来做。我知道我们可以使用Selenium RC来做到这一点,但我不想这样做。有没有人做过?我愿意升级到Selenium 2.20.0(最新版)。模仿'Enter'使用Selenium在Webtest中按键

回答

5

您可以将回车键发送到元素。但是,您不能按Enter键来确认下载对话框。

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