RON12345
RON12345

Reputation: 123

How to press "Enter" in Selenium WebDriver (Nunit Test Case) written in C#?

I am trying to create a automation framework with nunit + Selenium + c#

Our webadmin is based on Devexpress framework hence I can't click button by it's "ID" or atleast I dont know how to. The subtitute to this is simply pressing "Enter" button. I have already tried

driver.FindElement(By.XPath("String")).SendKeys(Keys.Enter);

Upvotes: 7

Views: 36427

Answers (4)

Sheetal Samnani
Sheetal Samnani

Reputation: 1

Keys.Return() solved the issue for pressing enter

Upvotes: 0

user2330678
user2330678

Reputation: 2311

Use below code to click on an invisible button.

 IWebElement tmpElement = Driver.FindElement(By.Id("invisibleButton"));
 var executor = (IJavaScriptExecutor)Driver;
 executor.ExecuteScript("arguments[0].click();", tmpElement);
 wait.Until(d => { return d.Title.Equals("pageTitle"); });

Upvotes: 1

MushtaqAR
MushtaqAR

Reputation: 71

using OpenQA.Selenium.Interactions;

Actions builder = new Actions(driver);        
builder.SendKeys(Keys.Enter);

For more information: Typing Enter/Return key in Selenium

Upvotes: 7

Akbar
Akbar

Reputation: 1525

RON, there is a possibility that DOM is taking time to load after the GoToUrl call. Increase the implicit wait time so that findElement waits more time before throwing any exception. Or use explicit wiat --- http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

If still this doesnt work then use Actions class -- http://www.guru99.com/keyboard-mouse-events-files-webdriver.html

Upvotes: 0

Related Questions