Press Enter Key in Selenium RC with C#
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");
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, 2022Comments
-
Ranadheer Reddy almost 2 years
How to press Enter using Selenium RC using C#?
I am working with a
SearchBox
usingSelenium
. 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 about 12 yearsimport org.openqa.selenium.Keys; itself giving error. i am working with Visual studio. c#
-
Ranadheer Reddy about 12 yearsHere what is mean by locator of element? is dat mean xpath of my textBox ?
-
Rohit Ware about 12 yearsYes, just put xpath of text-box
-
Ranadheer Reddy about 12 yearsHmm. I tried.But not working. No error. But Enter is not working
-
Ranadheer Reddy about 12 yearsWhen i debug it, it is saying Expression was evaluated but has no Value.
-
Petr Janeček about 12 yearsOh, 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 about 12 yearsquicksearchtextcriteria is ID of field???If yes then try to use locator as ID=quicksearchtextcriteria...I think that was xpath error message
-
Nashibukasan about 12 yearsOr: searchBox.SendKeys("Text to search" + OpenQA.Selenium.Keys.Enter);
-
user85 over 5 yearsThe 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 over 5 yearsThe 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 over 5 yearsWhen 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 over 5 yearsI fixed the links. Note that this answer is 6 years old now, and Selenium RC is looong gone. Go for WebDriver!