Typing the Enter/Return key using Python and Selenium

croixhaug picture croixhaug · Oct 27, 2009 · Viewed 636.5k times · Source

I'm looking for a quick way to type the Enter or Return key in Selenium.

Unfortunately, the form I'm trying to test (not my own code, so I can't modify) doesn't have a Submit button. When working with it manually, I just type Enter or Return. How can I do that with the Selenium type command as there is no button to click?

Answer

Ralph picture Ralph · Aug 18, 2011
import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.RETURN);

The import statement is for Java. For other languages, it is maybe different. For example, in Python it is from selenium.webdriver.common.keys import Keys