public override string DoImpl()
{
var buttonName = this.Action == With.Accept ? "LeftButton" : "RightButton";
var popups = VisualTreeHelper.GetOpenPopups();
foreach (var popup in popups)
{
var popupChild = popup.Child;
var element = (FrameworkElement)Finder.GetDescendantsBy(popupChild, new By("name", buttonName)).FirstOrDefault() as Button;
if (element == null)
{
continue;
}
var peer = new ButtonAutomationPeer(element);
var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
if (invokeProv == null)
{
continue;
}
invokeProv.Invoke();
return null;
}
throw new AutomationException("No alert is displayed", ResponseStatus.NoAlertOpenError);
}