简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM