This project is read-only.

Cannot get UIItem for Vista "Open" button

Mar 16, 2009 at 10:27 AM
This has really got me baffled. Running some existing test code under Vista shows up a problem whereby the Open button on the standard file open dialog cannot be found.

I have tried Get<Button>  using the text and/or the automation id and/or the control type

I have tried iterating through the Items UIItemCollection on the window but it skips over the Open button!

I have tried specifying the index of the control but again it skips over it and returns the next one (Cancel).

Bizarrely, debugging into this, doing an {window}.Items.Count  in the code will give  'n' items

Doing the same in the watch window gives  'n+1'  !!!!  The +1 being the open button!

HELP!  :-)

Mar 25, 2009 at 12:10 PM
does UISpy recognize this button?
can you do a window.LogStructure() and check the output
Mar 26, 2009 at 12:23 PM
UISpy does recognise the button as a button and named "Open".

LogStructure reports:

 AutomationId: 1
    ControlType: ControlType.Pane
    Name: Open
    Bounding rectangle: 1051,477,75,23
    ClassName: Button
    IsOffScreen: False

But like I said, iterating through the UIItems in the collection seems to skip this control.

Apr 6, 2009 at 1:36 PM
any thoughts?
Mar 23, 2012 at 7:21 AM
Edited Mar 23, 2012 at 7:22 AM

Yup with the Vista and later OSes, the Open button is no longer a button per se

  AutomationId: 1
    ControlType: ControlType.Pane
    Name: Open
    ClassName: Button
    FrameworkId: Win32

    AutomationId: 2
    ControlType: ControlType.Button
    Name: Cancel
    ClassName: Button
    FrameworkId: Win32


More importantly, the Open UIElement does not support the InvokePattern - which clicks the button.

Possible Solutions:

  • if GetById<Button>() fetch returns null i.e. on Win7-like platform, try this instead

var button = openFileDialog.Get<Panel>(SearchCriteria.ByAutomationId(AutomationIds.OpenButton));

  • Press Enter instead to invoke default button - MainWindow.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN);
  • Use Accelerators / keyboard shortcut - Alt + O