Lack of Find.AllByClass()?

3 posts, 0 answers
  1. Andrew
    Andrew avatar
    4 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    I am playing around with the framework and I was just wondering why there is a Find.ById() but not a Find.AllByClass<T>() or Find.AllByClass()?

    Am I missing something whats the best way to figure something out like this? Should I just create an extension method using some other method?
  2. Andrew
    Andrew avatar
    4 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    Well, I guess since no one has responded I'll go with:

    public static IEnumerable<T> AllByClass<T>(this Find find, string className) where T : HtmlControl, new()
                return find.AllControls<T>().Where(x => x.CssClass.Contains(className));
  3. Stoich
    Stoich avatar
    1 posts

    Posted 23 Dec 2010 Link to this post

    Hello Andrew,
      you can use Find.ByExpression
    For example if you have the following HTML code:
    <p class="mc"> This is a paragraph </p><br>
    You want to get the paragraph by class and paste its content to the Log file.
    You can use the following code:
    Element e = Find.ByExpression("class=mc");
    Log.WriteLine("This is the text conecnt:"+e.InnerText);

    You can also specify what element you're looking for like this:
    This will return the first HTML button that fits the description (class=mc).
    You can also use Find.AllByExpression which returns a collection.

    You can find more info on Find.ByExpression here.

    I hope this helps - let me know if you need anything else!

    Best wishes,
    the Telerik team
    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top