Finding Elements On a Wwebpage



  • 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?



  • 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.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2