Ranadheer Reddy
Ranadheer Reddy

Reputation: 4324

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

Upvotes: 8

Views: 41056

Answers (7)

Petr Janeček
Petr Janeček

Reputation: 38424

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.

Upvotes: 8

Illidan
Illidan

Reputation: 4237

This is how it done with C#:

webElement.SendKeys(Keys.Return);

Upvotes: 3

talha2k
talha2k

Reputation: 1

Try this:

import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.RETURN)

References:

Typing Enter/Return key in Selenium

http://asynchrony.blogspot.com/2008/11/enter-key-press-in-selenium.html

Hope this helps.

Upvotes: 4

Amit Shakya
Amit Shakya

Reputation: 1476

You can use clickAt("locator",""); If keyPress is not working. It will work for sure.

Upvotes: 0

Nashibukasan
Nashibukasan

Reputation: 2028

I believe you can also use the 'Submit' method. (Though I use Selenium 2, so I'm guessing perhaps this is not possible in Selenium RC? Sorry if so).

//First you need to find the searchBox and fill it, once doing so call
searchBox.Submit();

Upvotes: 2

Rohit Ware
Rohit Ware

Reputation: 2002

Use this one

selenium.keyDown("locator of element", "\\13");

Upvotes: 0

Alp
Alp

Reputation: 29739

Try this:

selenium.KeyPressNative("13");

Upvotes: 1

Related Questions