https://video2.skills-academy.com/en-us/dotnet/api/system.windows.automation?view=net-5.0 that namespace is strictly for WPF only.
To unit test a WinForms app, you might try to use https://github.com/microsoft/WinAppDriver on Windows 10.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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();
}
Code snippet for toolstrip:
enter code here
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1,
this.toolStripComboBox1,
this.toolStripButton2});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Text = "toolStrip1";
//
// toolStripButton1
//
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Text = "toolStripButton1";
//
// toolStripComboBox1
//
this.toolStripComboBox1.Name = "toolStripComboBox1";
this.toolStripComboBox1.Size = new System.Drawing.Size(121, 25);
//
// toolStripButton2
//
this.toolStripButton2.Name = "toolStripButton2";
this.toolStripButton2.Text = "toolStripButton2";
//
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton toolStripButton1;
private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;
private System.Windows.Forms.ToolStripButton toolStripButton2;
https://video2.skills-academy.com/en-us/dotnet/api/system.windows.automation?view=net-5.0 that namespace is strictly for WPF only.
To unit test a WinForms app, you might try to use https://github.com/microsoft/WinAppDriver on Windows 10.