问题
I am not an expert in LINQ. Here is what I am trying to do.
A. I am finding the collection of the elements of a page using the selenium webdriver API
private ReadOnlyCollection<IWebElement> ReturnPageElements()
{
return Driver.FindElements(PageElementSelector);
}
where PageElementSelector is all the html tags(since it's long list, I did not paste it here). I then instantiate this method inside my BaseClass Constructor.
B. I am using the following to find THE target element
public IWebElement FindButtonById(string Id)
{
return ReturnPageElements().FirstOrDefault(webElement => webElement.TagName == "button" && webElement.GetAttribute("id") == Id);
}
and here is the use of this inside my test
public PlansPage ClickDeletePlanButton()
{
FindButtonById("btnDelete").Click();
return new PlansPage(Driver);
}
My issue is some of the pages have a lot of elements and LINQ tremendously slow down the test execution. This is a good concept I want to implement which can save me a lot of time and code duplication. Is there any way to increase the performance of this query? I do not have to use LINQ, any solution is appreciated
来源:https://stackoverflow.com/questions/24985370/linq-performance-issue-while-trying-to-find-element-collection-by-tag-name-and-t