LINQ performance issue while trying to find element collection by tag name and then find a specfic one by id or text using selenium webdriver

拥有回忆 提交于 2020-01-05 08:49:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!