Sign in to follow this  
Followers 0
EileenW

How to click a tab using its name?

15 posts in this topic

Hi,

The application I want to automate has multiple tabs and all the tabs are of the same Class "SysTabControl32" and Instance "1". I found that in method ControlCommand you can move to the next tab to the right or to the left, but I am wondering if there is a way to move to a tab using the tab name? That way we don't need to care about which tab we are right now, and I think the script would be more robust at handling GUI changes (e.g. tab layout order changes).

Thanks,

Eileen

Share this post


Link to post
Share on other sites



Hi,

The application I want to automate has multiple tabs and all the tabs are of the same Class "SysTabControl32" and Instance "1". I found that in method ControlCommand you can move to the next tab to the right or to the left, but I am wondering if there is a way to move to a tab using the tab name? That way we don't need to care about which tab we are right now, and I think the script would be more robust at handling GUI changes (e.g. tab layout order changes).

Thanks,

Eileen

I doubt you will find a better method than you are already using. Move left untill the tab name doesn't change or is the tab name you want, If it doesn't change move right until the tab is what you want or it doesn't change. SysTabControl32 is the tabcontrol which contains all the tabbed pages so it will be the same for all tabs.

You can send a message to a tab control to select a tab by index, and you can send a message to get the index of the currently selected tab. So if you knew the index you could do what you want, or once you have selected each tab you can get its index so that when you select next time you just have to send a message with the index.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi Martin,

Can you give some more detail on how to send a message with the index? Say I have used ControlCommand with "CurrentTab" command to find out the index of a specific tab (is that the right way to get the index?), so next time how do I move to this tab using the index?

As I'm new to AutoIt please bear with me if my question is too obvious. ;)

Thanks,

Eileen

Share this post


Link to post
Share on other sites

_GUICtrlTab_FindTab() is supposed to work, but the Tab controls are pretty much botched up right now. You could try to pull out and change the _GUICtrlTab_GetItem() function to use $TCIF_TEXT instead of '$TCIF_ALLDATA', which will fix getting the correct index, but then you'll have to use the index to calculate movement using a mix of ControlCommand($hWnd,"",$hTabControl,"CurrentTab","") and multiple ControlCommand($hWnd,"",$hTabControl,$sDir,"") [where $sDir = "Right" or "Left"]

Share this post


Link to post
Share on other sites

I think it will be easier to use Gui Tab controls. I do not know of a way to return the tab name with ControlCommand. Here is a sample...just change "Your Window Title" and "Your Search Text" (the string name of the Tab you want focused) with the relevant values for your situation. Let me know if this works for you.

#include<GuiTab.au3>
WinWait('Your Window Title')
$hTab = ControlGetHandle('Your Window Title', '', 'SysTabControl321')
$tIndex = _GUICtrlTab_FindTab($hTab, 'Your Search Text', True, 0)
If $tIndex = -1 Then
    MsgBox(0, 'ERROR', 'Cannot Find Tab')
Else
    _GUICtrlTab_SetCurFocus($hTab, $tIndex)
EndIf

Share this post


Link to post
Share on other sites

Hi Martin,

Can you give some more detail on how to send a message with the index? Say I have used ControlCommand with "CurrentTab" command to find out the index of a specific tab (is that the right way to get the index?), so next time how do I move to this tab using the index?

As I'm new to AutoIt please bear with me if my question is too obvious. :)

Thanks,

Eileen

Firstly Varian has shown a good example which also shows the way to do it and that I was wrong to say you wouldn'y find a better way; I didn't know the _GuiCtrlTab_FindTab function.;)

But to answer your question, have a look at the GuiTab.au3 udf in the includes folder for AutoIt. Most of the functions use messages.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I think it will be easier to use Gui Tab controls. I do not know of a way to return the tab name with ControlCommand. Here is a sample...just change "Your Window Title" and "Your Search Text" (the string name of the Tab you want focused) with the relevant values for your situation. Let me know if this works for you.

#include<GuiTab.au3>
WinWait('Your Window Title')
$hTab = ControlGetHandle('Your Window Title', '', 'SysTabControl321')
$tIndex = _GUICtrlTab_FindTab($hTab, 'Your Search Text', True, 0)
If $tIndex = -1 Then
    MsgBox(0, 'ERROR', 'Cannot Find Tab')
Else
    _GUICtrlTab_SetCurFocus($hTab, $tIndex)
EndIf

Hi Varian,

Thank you for your answer. However when I tried it, I got a "Cannot Find Tab" Error box. Note that I have replaced the window title with my application window title and search text with the tab name. I have tried different tabs and none of them worked. Can you help me more here?

Thanks,

Eileen

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hi Varian,

Thank you for your answer. However when I tried it, I got a "Cannot Find Tab" Error box. Note that I have replaced the window title with my application window title and search text with the tab name. I have tried different tabs and none of them worked. Can you help me more here?

Thanks,

Eileen

What application or window are we talking about here. Some MS controls resist (some of) AutoIT's GUI fuctions (Listview & Tab functions especially). I would like to help & perhaps if I can reproduce the problem on my end I can help with a solution. A few other questions:

What is your OS?

What is your OS's Architecture (x86 or x64)?

What version of AutoIT are you running?

Do the Tabs on your app remain in a constant order & amount (always the same number of tabs in the same order)?

Does your app remember the last Tab focused and does it start with the last selected tab?

EDIT: Since ControlCommand works, you may be able to identify the selected IF the the text in the Window (or a control's text) changes

Edited by Varian

Share this post


Link to post
Share on other sites

I have already mentioned the broken _GUICtrlTab_FindTab() functionality in my post, and a solution. The tab functions fail for me even on Internet Explorer's properties sheet. I've already coded my own solution though, and I don't have the time to fix all of the broken standard UDF's just now.

Share this post


Link to post
Share on other sites

What application or window are we talking about here. Some MS controls resist (some of) AutoIT's GUI fuctions (Listview & Tab functions especially). I would like to help & perhaps if I can reproduce the problem on my end I can help with a solution. A few other questions:

What is your OS?

What is your OS's Architecture (x86 or x64)?

What version of AutoIT are you running?

Do the Tabs on your app remain in a constant order & amount (always the same number of tabs in the same order)?

Does your app remember the last Tab focused and does it start with the last selected tab?

EDIT: Since ControlCommand works, you may be able to identify the selected IF the the text in the Window (or a control's text) changes

Here are some more information:

The application is developed in C++ and MFC.

I was using WinXP (32bit) when trying your script.

AutoIt version is V3.3.6.1

The tabs on my app remain in a constant order & amount, but it could change when development changes.

The app does NOT remember the last tab focused, and it always start with the first tab focused.

Share this post


Link to post
Share on other sites

I have already mentioned the broken _GUICtrlTab_FindTab() functionality in my post, and a solution. The tab functions fail for me even on Internet Explorer's properties sheet. I've already coded my own solution though, and I don't have the time to fix all of the broken standard UDF's just now.

Sorry I didn't read your previous post very carefully because as I'm new to autoIt, modifying its library seems a little too advanced for me at this point ;)

Honestly I am surprised about the tab problem as tab is very common in Windows application.

Comparing to having to modify the source code, I would probably prefer going back to controlCommand, even though that's not the most effective way to move between tabs.

Thanks,

Eileen

Share this post


Link to post
Share on other sites

Eileen, understandable. Perhaps when I have time I'll submit a bug report - but there's a number of functions in that UDF that don't work, and they rely on a number of other UDF's as well as internal functions that makes it more difficult to debug. I would put up my own code, but I too use my own UDF's to work with the tabs.. sorry

Perhaps an alternative is to use the AutoIt window info tool on each tab to see what visible text is there when you switch tabs. That way, you can just check for some unique text as you rotate through the tabs.. it's a kludge, but it might work ;)

Share this post


Link to post
Share on other sites

Thanks for your help, I'll try this way for now. And please post a note on the thread if the tab functions do get fixed some day ;)

Share this post


Link to post
Share on other sites

Fixed :bye:

Share this post


Link to post
Share on other sites

warezoogle3, necroing posts this old is generally discouraged on this forum, especially when you're not adding anything to the thread itself. As this member has not been active in almost two years, I doubt this will do them any good ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0