Press Enter Key in Selenium RC with C#

33,534

Solution 1

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.

Solution 2

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.

Solution 3

This is how it done with C#:

webElement.SendKeys(Keys.Return);

Solution 4

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();

Solution 5

Try this:

selenium.KeyPressNative("13");
Share:
33,534
Ranadheer Reddy
Author by

Ranadheer Reddy

Currently am working as a software developer in Hyderabad, India. I love to learn new technologies. I like blogging too. And my Rule: Enjoy the life. It comes only Once :-)

Updated on July 09, 2022

Comments

  • Ranadheer Reddy
    Ranadheer Reddy almost 2 years

    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

  • Ranadheer Reddy
    Ranadheer Reddy about 12 years
    import org.openqa.selenium.Keys; itself giving error. i am working with Visual studio. c#
  • Ranadheer Reddy
    Ranadheer Reddy about 12 years
    Here what is mean by locator of element? is dat mean xpath of my textBox ?
  • Rohit Ware
    Rohit Ware about 12 years
    Yes, just put xpath of text-box
  • Ranadheer Reddy
    Ranadheer Reddy about 12 years
    Hmm. I tried.But not working. No error. But Enter is not working
  • Ranadheer Reddy
    Ranadheer Reddy about 12 years
    When i debug it, it is saying Expression was evaluated but has no Value.
  • Petr Janeček
    Petr Janeček about 12 years
    Oh, sorry, my bad. That was Java, I didn't recognize C# from the snippet. Isn't there an alternative in C#? Maybe not, I don't know.
  • Rohit Ware
    Rohit Ware about 12 years
    quicksearchtextcriteria is ID of field???If yes then try to use locator as ID=quicksearchtextcriteria...I think that was xpath error message
  • Nashibukasan
    Nashibukasan about 12 years
    Or: searchBox.SendKeys("Text to search" + OpenQA.Selenium.Keys.Enter);
  • user85
    user85 over 5 years
    The link for c# alternative isn't working. Is there a c# alternative to this - {code} selenium.type("locator", "Any text" + Keys.ENTER); {code}
  • Su Llewellyn
    Su Llewellyn over 5 years
    The error message for the bad links is: The requested URL /svn/trunk/docs/api/dotnet/html/T_OpenQA_Selenium_Keys.htm was not found on this server. That’s all we know.
  • Su Llewellyn
    Su Llewellyn over 5 years
    When I try this, I get the following error in Visual Studio 2017: "Argument 1 cannot convert from 'System.Windows.Forms.Keys' to 'string' - the API SendKeys requires a string.
  • Petr Janeček
    Petr Janeček over 5 years
    I fixed the links. Note that this answer is 6 years old now, and Selenium RC is looong gone. Go for WebDriver!