Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 235
RON12345 Avatar asked Jul 09 '13 15:07

RON12345


People also ask

How do I press enter in Selenium Webdriver?

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 does Selenium Webdriver handle Enter key?

To specify ENTER button functionality in Selenium webdriver we have to use the method sendKeys. To simulate pressing the ENTER button,we have to add the statement import org. openqa. selenium.

How do you send enter Tab keys in the Webdriver?

webElement. sendKeys(Keys. TAB); //This will enter the string which you want to pass and will press "Tab" button .


2 Answers

using OpenQA.Selenium.Interactions;

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

For more information: Typing Enter/Return key in Selenium

like image 155
MushtaqAR Avatar answered Nov 01 '22 12:11

MushtaqAR


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"); });
like image 30
user2330678 Avatar answered Nov 01 '22 14:11

user2330678