title: Selenium Web Driver C# InvalidCastException for List of WebElements after JavascriptExecutor
body: <p>I'm using Selenium web driver with Visual Studios 2010 in C#. 
  I'm using a jQuery to filter out a list of divs and use Selenium to double click them. However, no matter what I do, I can't seem to get rid of the InvalidCastException.      </p>
  
  <p>Here is the code that I wrote:</p>
  
  <pre><code>IWebDriver m_driver = new ChromeDriver();
  IJavaScriptExecutor js = m_driver as IJavaScriptExecutor;
  string jsQuery = [insert some query here that returns list of divs];
  object result = js.ExecuteScript(jsQuery);
  
  System.Collections.ObjectModel.ReadOnlyCollection&lt;IWebElement&gt; list = (System.Collections.ObjectModel.ReadOnlyCollection&lt;IWebElement&gt;)result;
  </code></pre>
  
  <p>The result does return a list of webelements though, but for some reason, sometimes the code above runs fine and casts and other times it doesn't on ChromeDriver. When it doesn't work, the last line of code provided fails with the following: </p>
  
  <pre><code>"Unable to cast object of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]' to type 'System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]'."
  </code></pre>
  
  <p>On InternetExplorerDriver, it fails almost all the time with the following:</p>
  
  <pre><code>Unable to cast object of type 'OpenQA.Selenium.Remote.RemoteWebElement' to type 'System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]'.
  </code></pre>
  
  <p>I have tried casting it to RemoteWebElement for IE, but that doesn't work either, because it sees RemoteWebElement and not a list of RemoteWebElements, and hence I can't enumerate them later.</p>
  
  <p>Any clues as to why?</p>