Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typing the Enter/Return key in Selenium

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?

like image 828
croixhaug Avatar asked Oct 27 '09 06:10

croixhaug


People also ask

How do I enter enter and text in Selenium?

You can simulate hit Enter key by adding "\n" to the entered text. For example textField. sendKeys("text you type into field" + "\n") .

How do I return text in Selenium?

In simple words, whatever is displayed as text on the browser will be returned as-is by the getText() method. If there is no text corresponding to a web element an empty string is returned.

What is the difference between keys enter and keys return in Selenium?

When using it normally with a browser, enter key selects a single keyword and adds it to the list of keywords. With Selenium however enter key sends the form and return key selects a single keyword. You may use \n rather.


1 Answers

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

like image 89
Ralph Avatar answered Oct 02 '22 22:10

Ralph