I'm dealing with a method to query web elements. and I want let users to choose which kind of elements They are want to choose. So I have Following code:
public static List<IWebElement> getItemsByType(IWebDriver driver, string typename, Expression<Func<IWebElement, bool>> expression)
{
return driver.FindElements(By.TagName(typename)).ToList().AsQueryable().Where(expression).ToList();
}
Here is the expression sample:
Expression<Func<IWebElement, bool>> expression = t => ((t.GetAttribute("type").ToString() == "button") && (t.FindElements(By.XPath("ancestor::table")).Count == 0));
For first step,I want to read this kind of lamda expression from textbox. The root issue is: How can I convert string to this kind of expression ?
Any help is appreciate !