FindElements By JQuery locator

Lots of websites use JQuery, and JQuery selector has more features than Css locator, such as contains etc. So try to use Javascript Executor to execute JQuery selector and return the WebElements.

public static IEnumerable<IWebElement> FindElementsByJQuery(ISearchContext context, string locator)
{

	var jsContext = context as IJavaScriptExecutor;

	if (jsContext != null)
	{
		var jObjects = (Dictionary<string,object>)jsContext.ExecuteScript(string.Format("return jQuery(\"{0}\")", locator));

		foreach (var o in jObjects)
		{
			if (!(o.Value is IWebElement))
			{
				continue;
			}
			yield return (IWebElement) o.Value;
		}
	}
}