title: C# Selenium Executing click() via IJavaScriptExecutor causing page to refresh
body: <p>I am trying to click on an element which sometimes has an invisible overlay, although it is clickable for me within the browser itself.  This was occasionally throwing an exception saying the element could not be clicked because it was obscured by another element.</p>
  
  <p>After checking SO, I found that others were claiming that executing a javascript click() call rather than Seleniums implementation of WebElement.Click would solve the problem.  So I tried it, and the page is refreshing rather than the element being clicked.</p>
  
  <pre><code>public class Scraper : INotifyPropertyChanged
  {
  
      public List&lt;string&gt; Matches { get; set; } = new List&lt;string&gt;();
      public int MatchCount { get; set; }
      public string Name { get; set; }
      public string StartUrl { get; set; }
      public string RegexPattern { get; set; }
      public By NextPageButtonSelector { get; set; }
      public int WaitTimeout { get; set; } = 20;
  
      public event EventHandler&lt;Match&gt; NewMatchFound;
      public event PropertyChangedEventHandler PropertyChanged;
  
      public async Task&lt;List&lt;Match&gt;&gt; ScrapeAsync(IWebDriver driver, PauseOrCancelToken pct)
      {
          var newMatches = new List&lt;Match&gt;();
          try
          {
              await Task.Run(async () =&gt;
              {
                  driver.Navigate().GoToUrl(StartUrl);
                  do
                  {
                      await pct.PauseOrCancelIfRequestedAsync();
                      var mc = Regex.Matches(driver.PageSource, RegexPattern);
                      foreach (Match m in mc)
                      {
                          if (!Matches.Contains(m.Value))
                          {
                              newMatches.Add(m);
                              Matches.Add(m.Value);
                              MatchCount++;
                              OnNewMatchFound(m);
                          }
                      }
                      var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(WaitTimeout));
                      wait.Until(ExpectedConditions.ElementToBeClickable(NextPageButtonSelector));
                      var nextPageButton = driver.FindElement(NextPageButtonSelector);
                      ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", nextPageButton);
                      ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", nextPageButton);
                  } while (true);
              });
          }
          catch (Exception ex)
          {
              System.Diagnostics.Debug.WriteLine(ex);
          }
  
          return newMatches;
      }
  
      private void OnNewMatchFound(Match m)
      {
          if (NewMatchFound != null)
          {
              NewMatchFound(this, m);
          }
      }
  }
  </code></pre>