title: Selenium click doesn't work with angularjs ng-click event
body: <p>I'm looking to verify a particular external function is called on a ng-click event. The input declaration is as follows. This works fine in the browsers, so there are no problems functionally, only during testing with Selenium I'm not seeing the correct result. myFunction is calling an external myExternalFunction, which is the behaviour I'm trying to validate. We already have jasmine tests with spies validating this behaviour in a different environment, but Selenium is needed anyways. Also we don't use protractor at the moment. I'm looking for a solution with Selenium.</p>
  
  <pre><code>&lt;input class="myClass" ng-click="myFunction()"&gt;
  </code></pre>
  
  <p>In the C# Selenium tests, I'm writing:</p>
  
  <pre><code>// Creating the mock external function since the context doesn't have it.
  IJavaScriptExecutor executor = WebDriver as IJavaScriptExecutor;
  executor.ExecuteScript("window.called='false'");
  executor.ExecuteScript("window.external = {}");
  
  // The behavior will be just setting the called variable to true.
  // We will retrieve the variable and check the value to see if the function was called.
  executor.ExecuteScript("window.external.myExternalFunction = function() {window.called = 'true';}");
  
  // Select the element - there's only one element with this classname
  IWebElement element = WebDriver.FindElement(By.ClassName("myClass"));
  string value = "";  
  // Verified via debugging that the element is actually valid.
  // Tried the following options.
  
  // 1) Just click and wait for event propagation - didn't work.
  element.Click(); // Didn't do anything so added a Thread Sleep to make sure.
  Thread.Sleep(1000);
  value = WebDriver.ExecuteJavaScript&lt;string&gt;("return window.called;"); // returns false - expected to be true.
  
  // 2) Use the actions to focus and click.
  IWebDriver driver = WebDriver;
  Actions a = new Actions(driver);    
  a.MoveToElement(element).Perform();
  a.MoveToElement(element).Click().Perform();
  Thread.Sleep(1000);
  value = WebDriver.ExecuteJavaScript&lt;string&gt;("return window.called;"); // returns false - expected to be true.
  
  // 3) Select and click via javascript instead.
  executor.ExecuteScript("angular.element('.myClass').click();");
  Thread.Sleep(1000);
  value = WebDriver.ExecuteJavaScript&lt;string&gt;("return window.called;"); // returns false - expected to be true.
  </code></pre>
  
  <p>I'm pretty much out of ideas at this stage. Is there no way to make Selenium play nice with angularjs? Similar question here: <a href="https://stackoverflow.com/questions/32499174/selenium-click-event-does-not-trigger-angularjs-ng-click">Selenium click event does not trigger angularjs ng-click</a> without conclusive answer.</p>