This project is read-only.

ElementNotEnabledException when editing a TextBox

Oct 18, 2010 at 9:29 AM


I'm having trouble entering text to a TextBox. My code returns an ElementNotEnabledException, when I try to change the text property, use the Enter function or the SetValue function.

My code is like this:

TextBox tb = dglReport.Get<TextBox>(SearchCriteria.ByAutomationId("MyTextBox"));
if (tb != null && tb.Enabled)

The strange thing is that before I call Enter(), Enabled is true, but after I call the function it throws an error and Enabled becomes false.

Has anyone seen this before?

Oct 18, 2010 at 10:29 AM


strange, I think you can't reproduce this manually, right?


can you try


tb.BulkText = "500";



Oct 18, 2010 at 10:43 AM


It is the same here is the stack trace, if I try to use BulkText:

 Bricks.BricksException : Error invoking WinFormTextBox.set_BulkText  ----> System.Windows.Automation.ElementNotEnabledException : Exception of type 'System.Windows.Automation.ElementNotEnabledException' was thrown.

 D:\bricks\Bricks.RuntimeFramework\ReflectedObject.cs(69,0): at Bricks.RuntimeFramework.ReflectedObject.Invoke(MethodInfo methodInfo, Object[] arguments) D:\bricks\Bricks\DynamicProxy\DynamicProxyInterceptors.cs(20,0): at Bricks.DynamicProxy.DynamicProxyInterceptors.Process(IInvocation invocation, InterceptContext interceptedContext) d:\white\Core\Interceptors\CoreInterceptor.cs(29,0): at White.Core.Interceptors.CoreInterceptor.Intercept(IInvocation invocation) d:\OSS\Castle\Tools\Castle.DynamicProxy2\Castle.DynamicProxy\AbstractInvocation.cs(165,0): at Castle.DynamicProxy.AbstractInvocation.Proceed() at WinFormTextBoxProxy7e21cb975be14d2ea80213e0bff8c696.set_BulkText(String value)



Oct 18, 2010 at 3:04 PM


can you catch the exception, and debug to this point, after exception is thrown.

Is the control enabled or disabled for the user?

try to use TextPattern from UIAutomation to set the value. The same result?

if not it's a bug in White, otherwise it might be a bug in UIAutomation


.Net 4.0?








Oct 18, 2010 at 4:09 PM

First I'm using .Net 3.5.  

I check if the control is enabled before I try to enter the text. 

I'm not sure how to use TextPattern to set the value.

I don't have the white code so I can not debug into the Enter() function. 

But I still get the error ElementNotEnabledException, which is a System.Windows.Automation error.

Btw, thank for the response.


Oct 18, 2010 at 5:13 PM

I found the problem,  there was an event connected to the textbox. The eventhandler was shifting the text to the left:

void textBox_Enter(object sender, EventArgs e)
    TextBox textBox = (TextBox)sender;
    if (textBox.IsDisposed == false && textBox.Disposing == false 
        && left == false) 
         textBox.TextAlign = HorizontalAlignment.Left;

I managed to go around this by using, click and keyboard.enter.

Oct 20, 2010 at 7:20 AM

Go through this -

You will understand how to use TextPattern as Throndorin has suggested. It might work that way.