I'm trying to automate an installation wizard and I needed to click on a button that is not enabled.
I know that this can be done using Windows Messages, but I was wondering if there is already support in White or UIAutomation for this
For reference this doesn't work:
var invoke = (System.Windows.Automation.InvokePattern)setup.button("Next >").AutomationElement.GetCurrentPattern(System.Windows.Automation.InvokePattern.Pattern);
invoke.Invoke();
neither does this
var guiAutomation = new API_GuiAutomation("msiexec");
var setup = guiAutomation.windows()[0];
setup .bringToFront();
setup .button("Next >").mouse().click(); // this will work
setup .button("Next >").mouse().click(); // this will not work since the button is not enabled
The example above uses the White based API I added to the O2 Platform (see here an example of automating notepad)
I don't believe you can do this with UIAutomation: what you're asking for is something that goes beyond the remit of the UIAutomation framework. It is intended to let you do with code the same that you could otherwise do with mouse and keyboard. It is not designed as a general means of manipulating UI state.
You can directly call the Win32 function EnableWindow, which sends a Windows Message, just like you said.
I looked for that functionality in UIAutomation, but did not find it.
If you're using White
Mouse.Instance.Location = this.ClickablePoint;
Mouse.LeftDown();
Mouse.Instance.Location = point;
Mouse.LeftUp();
Clicking onto an enabled button is sooner related to fault injection techniques, rather than normal execution of an application.
Is this button disabled for the rest of the application's life cycle or will be enabled later? If the latter, why don't wait for enabling? By using do/while on element.Current.IsEnabled or the Wait-UIAButton cmdlet.