Friday, June 26, 2009

Check if control is Enabled

public bool IsEnabled(string controlId)
    {
        bool retValue = false;
        try
        {
            string disabled = _selObj.GetEval("selenium.browserbot.getCurrentWindow().getElementById('" + controlId + "').disabled");
            retValue = disabled.ToLower() == "true" ? false : true;
            if (retValue)
                Log.Info(DateTime.Now.ToString() + " : Control " + controlId + " is enabled.");
            else
                Log.Info(DateTime.Now.ToString() + " : Control " + controlId + " is disabled.");
        }
        catch (Exception ex)
        {
            Log.Error(DateTime.Now.ToString() + " : Error occured while determining if control " + controlId + " is enabled");
            throw new Exception("Error occured at SeleniumPage.IsEnabled on '" + controlId + "'", ex);
        }
    return retValue;
}

1 comment: