7

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);
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
RON12345
  • 123
  • 1
  • 3
  • 10
  • So why exactly doesn't `.Click` work? – Arran Jul 09 '13 at 15:51
  • I get this error with .Click 'ClassLibrary2.UnitTest1.TestMethod2: OpenQA.Selenium.ElementNotVisibleException : Element is not currently visible and so may not be interacted with' – RON12345 Jul 09 '13 at 16:14
  • Can you include in your query the html for the button?? – Abhijeet Vaikar Jul 09 '13 at 16:20
  • 'at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 1009 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 849 at ClassLibrary2.UnitTest1.TestMethod2() in C:\Users\Administrator\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 46 ' – RON12345 Jul 09 '13 at 16:22
  • my code looks like this ... [Test] public void TestMethod2() { driver.Navigate().GoToUrl("https://localhost/websearch"); driver.FindElement(By.Id("pcLogin_Panel1_txtUsername_I")).SendKeys("auto test1 "); driver.FindElement(By.Id("pcLogin_Panel1_txtPassword_I")).SendKeys("Exchange1"); driver.SendKeys(Keys.Enter).perform; driver.FindElement(By.Id("pcLogin_Panel1_btnLogon_B")).Click(); Assert.AreEqual("Web Admin - Dashboard", driver.Title); } – RON12345 Jul 09 '13 at 16:23
  • My Web interface is based on devexpress hence i can't select it by the object ID .. – RON12345 Jul 09 '13 at 16:26
  • Then your problem is nothing to do with "based on devexpress". What does the message say? It's says what you are trying to interact with simply isn't visible. Therefore you'll have the same issue using `SendKeys(Keys.Enter)`. Post the HTML of the page you are using and try to reproduce it on another website. – Arran Jul 09 '13 at 17:42
  • How can I press Enter with Selenium WebDriver using Java? – Ripon Al Wasim Sep 06 '13 at 09:36

4 Answers4

7
using OpenQA.Selenium.Interactions;

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

For more information: Typing Enter/Return key in Selenium

Community
  • 1
  • 1
MushtaqAR
  • 71
  • 1
  • 5
1

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"); });
Matt Ke
  • 3,599
  • 12
  • 30
  • 49
user2330678
  • 2,221
  • 14
  • 43
  • 67
0

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

Akbar
  • 1,513
  • 4
  • 20
  • 34
0

Keys.Return() solved the issue for pressing enter

Bussller
  • 1,961
  • 6
  • 36
  • 50