Ask a Question

Click on the selected item of a tabstrip control in WinForms.

ussainik
Occasional Contributor

Click on the selected item of a tabstrip control in WinForms.

I am trying to automate a winforms application and when I use the object spy, it says its a tab strip control name is tabstrip1. How do I click/select the different tabs based on the name?

 

I try something like this but it doesn't work

//Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.tabStrip1.Click(178, 14); I don't want 178,14, I want to click based on the name.
//Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.WinFormsObject("tabControlPanelSurvey")
Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.tabStrip1.Click("tabControlPanelSurvey");

tab.PNG

 

12 REPLIES 12
rraghvani
Trusted Contributor

Looking at your alias names, following the tree strucure,

 

EchoClientApplicationForm
splitContainerMain
SplitterPanel
splitContainerUpper
SplitterPanel2
tabControl
tabStrip1
tabControlPanelSurvey

 

Can you confirm the highlighted sections are correct?

 

tabStrip1 doesn't seem to have a child object named tabControlPanelSurvey.

ussainik
Occasional Contributor

Hi its correct until tabStrip1. "tabControlPanelSurvey" is the name of one of the tabs that I want to click on the tabStrip1.

rraghvani
Trusted Contributor

tabStrip1 doesn't have any child objects called tabControlPanelSurvey.

 

rraghvani_0-1678957796371.png

 

However, tabControl does have a child object called tabeControlPanelSurvey as well as tabStrip1, tabControlPanelFluideReplacem..etc.

 

If you were to do e.g. tabControl.tabStrip1.Click() or tabControl.Click("tabStrip1) then it may work.

 

Record a keyword test, then convert it to script. You will see how TC has recognised the objects.

ussainik
Occasional Contributor

I recorded a keyword test and tried all the options. When I say  "Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.tabControlPanelSurvey.Click();"

 

"Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.Click("tabControlPanelSurvey");

It says the object tabControlPanelSurvey does not exist.

rraghvani
Trusted Contributor

Are you able to use WinFormsObject Method to obtain the object, then perform a click?

 

See Addressing Objects in .NET Applications

ussainik
Occasional Contributor

Yes it shows the Name is WindFormsObject("tabstrip1")

rraghvani
Trusted Contributor

Have you tried the examples provided by TC, in my previous post?

ussainik
Occasional Contributor

Thanks I tried something like this but nothing works.. It says "Unable to find the object ClickItem("tabControlPanelSurvey", 2)"

Sys.Process("EchoClientUtility").WinFormsObject("EchoClientApplicationForm").WinFormsObject("splitContainerMain").WinFormsObject("SplitterPanel", "", 1).WinFormsObject("splitContainerUpper").WinFormsObject("SplitterPanel", "", 1).WinFormsObject("tabControl").ClickItem("tabControlPanelSurvey",2);

 

I am having to use not a good approach (like the default script it generates after keyword test),

Aliases.EchoClientUtility.EchoClientApplicationForm.splitContainerMain.SplitterPanel.splitContainerUpper.SplitterPanel2.tabControl.tabStrip1.Click(85, 18);

rraghvani
Trusted Contributor

Can you try this please,

var tabControl = Sys.Process("EchoClientUtility").WinFormsObject("EchoClientApplicationForm").WinFormsObject("splitContainerMain").WinFormsObject("SplitterPanel", "", 1).WinFormsObject("splitContainerUpper").WinFormsObject("SplitterPanel", "", 1).WinFormsObject("tabControl")
Sys.HighlightObject(tabControl); // Is the tab control highlighted?

var tabControlPanelSurvey = tabControl.WinFormsObject("tabControlPanelSurvey");
Sys.HighlightObject(tabControlPanelSurvey); // Is the tab control survey highlighted?

tabControlPanelSurvey.Click();

Are the controls highlighted correctly?

 

Can you also, click on each of the tabs, then run the above code again. Because "tabControlPanelSurvey" is greyed out, the page could be dynamically created when it's clicked on.

 

 

cancel
Showing results for 
Search instead for 
Did you mean: