Forum Discussion

reydimaano's avatar
reydimaano
Contributor
12 years ago

How to select each tab without knowing the url or tab title?

I have an IE browser opened which have 5 tabs.  The current selected tab is the last one (tab 5).  I want to jump to tab 2 without knowing the url.
  • I would never want to suggest Tanya wasn't right - she's way smarter with TC than me -  but I think a slight tweak to her code is required... I think her code in its current state is trying to click an entire array of tabs in a single click - while what you are looking to do is click the "nth" tab. With that in mind, blatantly stealing Tanya's code(!), and remembering arrays start at the 0th element:




    function ClickTabByNo(TabIndex) // Specify Tab Index as 1-5 "human form"


     


    {


     


      var tabPanel = Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand;


     


      var tabs = tabPanel.FindAll("ObjectType","TabButton");


     


      tabs = (new VBArray(tabs)).toArray();


     


      tabs[TabIndex - 1].Click();


     


    }

  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    I would never want to suggest Tanya wasn't right - she's way smarter with TC than me -  but I think a slight tweak to her code is required... I think her code in its current state is trying to click an entire array of tabs in a single click - while what you are looking to do is click the "nth" tab. With that in mind, blatantly stealing Tanya's code(!), and remembering arrays start at the 0th element:




    function ClickTabByNo(TabIndex) // Specify Tab Index as 1-5 "human form"


     


    {


     


      var tabPanel = Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand;


     


      var tabs = tabPanel.FindAll("ObjectType","TabButton");


     


      tabs = (new VBArray(tabs)).toArray();


     


      tabs[TabIndex - 1].Click();


     


    }

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Rey,


     


    Something like this:




    function Test()


    {


      var tabPanel = Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand;


      var tabs = tabPanel.FindAll("ObjectType","TabButton");


      tabs = (new VBArray(tabs)).toArray();


      tabs[2].Click();


    }




     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)


    Good catch, Steve :)


     


    In my defense, I would like to add that our syntax highlighter removed the [2] code from tabs[2].Click() in my script. I've reported this issue to our web team. Thanks!




  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Murugan,


     


    The cause of the issue may be related to this line:


    Set tabs = tabPanel.FindAll("TabStripWndClass","All")


     


    The second parameter of the FindAll method should be the value of the property specified as the first parameter. It's unlikely that the value of TabStripWndClass will be All. Please check this in the Object Browser.


     

  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Could u please correct my code plz..i m getting object required error function



    ClickTabByNo(TabIndex)

      Set tabPanel = Sys.Process("ERPQuickLauncher").VBObject("frmQL").VBObject("Tbsoptions")

      Set tabs = tabPanel.FindAll("TabStripWndClass","All")

      tabs =VBArray(tabs).toArray()

      call tabs(TabIndex-1).click

    End function