Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing Coded UI Tests in Visual Studio and need to know the best way to find elements on a page. Would it be better to use the element's class or some other attribute?

share|improve this question
up vote 1 down vote accepted

In my experience, it will greatly depend on how your developers choose to add attributes to elements. For example, if the element that you need to interact with has an ID, you can use that as a SearchProperty to assist in finding the element that you need:

objPage.SearchProperties.Add(HtmlControl.PropertyNames.Id, strID);
UITestControlCollection colControls = objPage.FindMatchingControls();

Using something like this will provide you with a collection of elements that match the specified criteria. I suggest playing around with these SearchProperties and examining your codebase to determine the best course of action for your Coded UI tests.

share|improve this answer
Ok great. This worked out fine Thanks – user7277 Mar 20 '14 at 19:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.