This is a migrated thread and some comments may be shown as answers.

Lack of Find.AllByClass()?

2 Answers 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Dec 2010, 10:44 PM
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 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 23 Dec 2010, 04:24 AM
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));
        }
0
Stoich
Telerik team
answered on 23 Dec 2010, 01:33 PM
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:
ActiveBrowser.NavigateTo("http://myExamplePage.html");
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:
Find.ByExpression<HtmlButton>("class=mc");
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,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Stoich
Telerik team
Share this question
or