I’m trying to access a toolstrip button in windows forms using button name in windows forms but facing null reference exception as end result. Normally I can access button using its name, but i am facing issue in accessing the button in toolstrip.
This issue occur in N unit framework and access button using automation element. Can anyone guide me for this issue ?
Code snippet for accessing button:
enter code here
public static AutomationElement WindowElement;
public void ClickButton()
{
object objPattern;
AutomationElement click = WindowElement.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "toolStripButton2"));
click.TryGetCurrentPattern(InvokePattern.Pattern, out objPattern);
((InvokePattern)objPattern).Invoke();
}