Niels van Reijmersdal
Niels van Reijmersdal

Reputation: 2045

What is the difference between find and findmatchingcontrols

Recently I started trying to handcode Coded-UI tests and run into an issue with the Find method.

The code I was using:

    Dim usernameControl As New UITestControl
    usernameControl.TechnologyName = "MSAA"
    usernameControl.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "user")
    usernameControl.Find()
    Dim usernameEdit As New WinEdit(usernameControl)
    usernameEdit.text = "myusername"

    Dim passwordControl As New UITestControl()
    passwordControl.TechnologyName = "MSAA"
    passwordControl.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "password")
    passwordControl.Find()
    Dim passwordEdit As New WinEdit(passwordControl)
    passwordEdit.text = "mypassword"

For some reason the passwordEdit.text function sets the text of the usernameEdit field. After I replaced the .Find() with .FindMatchingControls() it started working.

    usernameControl.Find() VS usernameControl.FindMatchingControls()

The documentation of these functions is extremely light, so light I cannot understand the difference.

The leads to the following questions:

Upvotes: 1

Views: 3581

Answers (2)

Shrivallabh
Shrivallabh

Reputation: 2893

Answering to your main question difference between UITestControl.Find and UITestControl.FindMatchingControls

After you apply Search or Filter on a perticular control, if you want your search for that control to be triggered then you use Find whose written type is Void. Whereas FindMatchingControls also triggers search with return type as collection of UITestControlCollection which has all the controls which are matching with given search or filter.

However there is one more control which returns bool that is TryFind

Upvotes: 0

Thomas Bouman
Thomas Bouman

Reputation: 608

Since I can't see the code you're trying to test this is going to be a guess:

You're looking for the control named password, since you're not specifying it's a WinEdit it might just find the first control named password. Which, if my guess is correct, could be the text above the password field.

Two options, rename the password control to PasswordInput and search specifically for that.

Second option is to search for a winEdit control instead of a UiTestControl:

Dim passwordEdit As New WinEdit()
passwordEdit.TechnologyName = "MSAA"
passwordEdit.SearchProperties.Add(WinWindow.PropertyNames.ControlName, "password")
passwordEdit.Find()
passwordEdit.text = "mypassword"

Upvotes: 1

Related Questions