I am using Microsoft.visualStudio.TestTools.UITesting for UI automation and found that sometimes for a particular buttons , button click takes more than expected time like 3 minutes or so. My code is as follows :
WebPage.Button_WithId_Click("OK");
definition of Button_WithId_Click
public void Button_WithId_Click(string itemId)
{
UiElement_ClickLocation(PrepareElementWithId(new HtmlButton(this.BrowserMainWindow.UiMobiControlDocument), itemId));
}
private HtmlControl PrepareElementWithId(HtmlControl uiElelement, string itemId)
{
return PrepareElementWithPropertyName(uiElelement, HtmlControl.PropertyNames.Id, itemId);
}
private HtmlControl PrepareElementWithPropertyName(HtmlControl uiElelement, string propertyName, string itemValue)
{
uiElelement.SearchProperties[propertyName] = itemValue;
return PrepareElement(uiElelement);
}
private HtmlControl PrepareElement(HtmlControl uiElelement)
{
HtmlControl controlToPrepare = uiElelement;
try
{
uiElelement.WaitForControlExist();
uiElelement.WaitForControlEnabled();
uiElelement.WaitForControlReady();
var matchingControl = uiElelement.FindMatchingControls();
if (matchingControl.Count == 1)
{
matchingControl[0].EnsureClickable();
return (HtmlControl)matchingControl[0];
}
return GetActiveControl(uiElelement);
}
catch (Exception)
{
//often element can not be clicked because it's obstructed by loading mask
//TODO: promote to app.config
const int webConsoleDefaultTimeout = 30000;
uiElelement.WaitForControlExist();
uiElelement.WaitForControlEnabled();
uiElelement.WaitForControlReady();
var matchingControl = uiElelement.FindMatchingControls();
if (matchingControl.Count == 1)
{
matchingControl[0].EnsureClickable();
return (HtmlControl)matchingControl[0];
}
return GetActiveControl(uiElelement);
}
}
There is no loading mask issue the control i.e button is available on the dialog box but takes approx 3 min to get clicked. what can be the resolution.