Visual Studio CodedUI – Another control is blocking the control

An issue I have been running into while trying to automate our web application is that some controls appear to be blocked. I would get error messages like this:

Another control is blocking the control. Please make the blocked control visible and retry the action.
 ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F003

I removed some of the lines to keep the message short. The main point here is the text “Another control is blocking the control.”

In most cases I have found the best way to fix this problem is to go deeper into your DOM. For instance, if you have a button with a div on it, and clicking the button gets you this message, try clicking the div. If that still gets you the error, try to go even deeper.

However, after going all the way down, I have found that sometimes this message keeps popping up. As I have been unable to find a good way to fix the problem, I made the following little utility method to circumvent it:

public static void ClickCenter(UITestControl control)
    Point location = control.BoundingRectangle.Location;
    location.Offset(control.BoundingRectangle.Width / 2, 
                    control.BoundingRectangle.Height / 2);

This method will click the center of the control you are trying to click. However, it does have the severe limitation that it will not check if the control is actually visible! This means that if you are trying to click a control that is currently not on screen (perhaps because your web page is too long and you would have to scroll to find it), it will happily click on something else. For instance, on another window or on your task bar. So use this method only as a last resort, if you are sure you cannot solve the problem another way and the control will always be clickable.

2 thoughts on “Visual Studio CodedUI – Another control is blocking the control

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.