This project is read-only.

Target Element cannot receive focus.

Apr 2, 2012 at 2:55 PM



I am trying to enter text into a TextBox but I get the error:            Target Element cannot receive focus.

I am selecting the textbox using the Automation ID and I am getting a non-null object (using White APIs)

It is a Win32 type of textbox.

Until recently I was able to click the same button, but maybe something has changed in the code or environment which is causing this.


Please let me know what can cause this error.


Apr 3, 2012 at 11:03 AM


The code is working fine when I run it using .EXE but throws the above stated exception when run from Visual Studio.


Any ideas, highly appreciated. :)

Apr 3, 2012 at 1:54 PM

Sorry the target element was indeed out of focus and on another window. Resolved!

Aug 24, 2012 at 4:31 PM

Hi skyw,

What do you mean the element is out of focus on another window? I have the same problem. I'm trying to setFocus on an automateElement but getting the 'target element cannot receive focus' exception. Please help. Thanks.

Aug 25, 2012 at 8:57 AM

What I meant was:

There can be more than one windows on the desktop at a time but only one can be in focus. You can bring another window in focus by simply clicking on it. Please make sure that the window - on which the target element is - is in focus. You may write a function that checks if the right window is in focus and no pop-ups notifications etc. have taken focus.

To quickly check this, add a sleep just before your setFocus call. During sleep, manually click the window first and then let setFocus execute.