Page 1 of 1

How to "click" on a FileControl element?

Posted: Thu Apr 18, 2013 1:08 pm
by JackK
Hi,
I have a dialog that need a file from disk for correct work. At the moment I have a FileControl item on the dialog which user must click to select the needed file. How may I open the dialog for file selecting automaticaly without the need of user action?

Thanks in advance.

Re: How to "click" on a FileControl element?

Posted: Thu Apr 18, 2013 3:20 pm
by hanya
So, you are using file control!
Try accessibility API to push the button inside the file control:

Code: Select all

Sub Snippet(Optional oInitialTarget As Object)
  Dim oControls As Variant
  Dim oXControl As Variant
  Dim oAccessibleContext As Variant
  Dim oAccessibleChild As Variant
  Dim oAccessibleContext2 As Variant
  Dim nAccessibleRole As Integer
  Dim oObj1 As Boolean

  oControls = oInitialTarget.getControls()
  oXControl = oControls(0)
  oAccessibleContext = oXControl.getAccessibleContext()
  
  oAccessibleChild = oAccessibleContext.getAccessibleChild(1)
  oAccessibleContext2 = oAccessibleChild.getAccessibleContext()
  nAccessibleRole = oAccessibleContext2.getAccessibleRole() ' should be PUSH_BUTTON
  
  oObj1 = oAccessibleContext2.doAccessibleAction(0)
End Sub
This code is recorded by MRI extension, oInitialTarget is the dialog object. The accessible role of the button that you have to find in the list of accessible child is css.accessibility.AccessibleRole.PUSH_BUTTON (44).