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.

Selenium locator extension

In Selenium, there are multiple locator functions, such as By.CssSelector By.XPath By.Id By.Name …… In my case, I would like to use different format, which I can call one method instead of so many, it would be easier to store the locator information somewhere else. The locator format would be ByMethod = selector to Find, for example: css=input[value=’clear’][type=button] So an extension method was created for this, here is the code snippet.