How to enable a button using UIAutomation or White

我的未来我决定 提交于 2019-12-13 03:08:10

问题


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)


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


If you're using White

Mouse.Instance.Location = this.ClickablePoint;

Mouse.LeftDown(); Mouse.Instance.Location = point; Mouse.LeftUp();



来源:https://stackoverflow.com/questions/5311800/how-to-enable-a-button-using-uiautomation-or-white

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!