Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

1 Answer 1

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 at 19:49

Your Answer

 
discard

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.