Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press Enter Key in Selenium RC with C#

How to press Enter using Selenium RC using C#?

I am working with a SearchBox using Selenium. In which I have to type some name and I have to press Enter to search.

There is no Submit button. So, I must use Enter.

I tried something like this

selenium.KeyPress("quicksearchtextcriteria", "13");

But doesn't work.

Please Help.

Note: I made a collection of possible ways to do this. See here: press enter key in selenium

like image 315
Ranadheer Reddy Avatar asked Apr 20 '12 08:04

Ranadheer Reddy


People also ask

How do I press Enter keyword in Selenium?

We can type Enter/Return key in Selenium. We shall use the sendKeys method and pass Keys. ENTER as an argument to the method. Also, we can use pass Keys.

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

Can Selenium Webdriver press keyboard keys?

You can easily issue a key press by using the send_keys command. This can be done to a specific element, or generically with Selenium's Action Builder (which has been documented on the Selenium project's Wiki page for Advanced User Interactions). Either approach will send a key press.


1 Answers

This can be achieved by Keys, and Enter.

Example in Java as I don't know C#:

import org.openqa.selenium.Keys;

//...

// this sends an Enter to the element
selenium.type("locator", Keys.ENTER);

// or even this - this sends the "Any text" and then confirms it with Enter
selenium.type("locator", "Any text" + Keys.ENTER);

From the Keys enum.

like image 103
Petr Janeček Avatar answered Nov 02 '22 02:11

Petr Janeček