Hi Olexandr,
Thank you for the sample.
I suggest that you work with the target controls via their native properties and methods. The following script demonstrates how to click the Test1 button:
Sub Main
Dim p, wMain, wRibbonBar, strItem
Set p = Sys.Process("SampleDNB")
Set wMain = p.WinFormsObject("Form1")
wMain.Activate
Set wRibbonBar = wMain.WinFormsObject("MainRibbon").WinFormsObject("OrganizationRibbonPanel").WinFormsObject("OrganizationCreateBar")
strItem = "Test1"
If clickItem(wRibbonBar, strItem) Then
Log.Message "The '" & strItem & "' item was successfully clicked."
Else
Log.Error "The '" & strItem & "' item was not found."
End If
End Sub
Function clickItem(wRibbonBar, strItem)
Dim oCont, itemCount, itemId, itemObj, bounds, mainBounds
clickItem = False
Set oCont = wRibbonBar.Items.Item(0)' Looks like It is the Container object
itemCount = oCont.SubItems.Count
For itemId = 0 To itemCount - 1
Set itemObj = oCont.SubItems.Item(itemId)
If SameText(itemObj.Text, strItem) Then
Set bounds = itemObj.AccessibleObject.Bounds
Set mainBounds = wRibbonBar.AccessibilityObject.Bounds
Log.LockEvents(1)
Call wRibbonBar.Click(bounds.Left - mainBounds.Left + bounds.Width / 2, bounds.Top - mainBounds.Top + bounds.Height / 2)
Log.UnlockEvents
Log.Event "The '" & strItem & "' item was clicked."
clickItem = True
Exit Function
End If
Next
End Function
Also, you can use MSAA to address the target buttons. To do this, you need to add the
WindowsForms* window class to the list of accepted MSAA windows (right-click your project in Project Explorer | Edit | Properties | Open Applications | MSAA). See the
Testing With Microsoft Active Accessibility article for information.
I hope this helps.