简体   繁体   中英

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);
using OpenQA.Selenium.Interactions;

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

For more information: Typing Enter/Return key in Selenium

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

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"); });

Keys.Return()解决了按enter的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM