selectWindow tab=1 only goes from the first tab in a loop, does not reassign a tab 0

Hi folks,

I upgraded from version 6.2.6 (oops had updates off) to 9.2.9 in Firefox and discovered that my looping functionality had changed.

I use this addon to automate identical repetitive tasks across multiple tabs so many of my scripts contain the instructions and then a selectWindow tab=1 to go to the next tab so that its usable for looping. Ive been doing this reliably for a while and it works with at least 10+ tabs this way.

With the new update it seems to only assign the very first tab as tab 0 and so the script fails after the first loop. When it gets to the end it assumes the second tab is still tab=1 and does not go another tab over. I did find an older thread that suggested using tab=${!LOOP} and that does work for sequential tabs. But sometimes I need it to skip 3 tabs over in the loop and cannot find a way to get it to perform the same actions.

Is there something here I am missing or a way to make it assign the current tab as tab 0 before it loops?

I tested with this one, and it works. But maybe I do not understand the issue :thinking:

→ Can you post a test macro?

{
  "Name": "DemoTabs",
  "CreationDate": "2024-7-27",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ui.vision/demo/tabs",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "linkText=Open new web page in new browser tab",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "assertTitle",
      "Target": "*1* TAB1",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=0",
      "Value": "",
      "Description": ""
    }
  ]
}

This is one I used regularly, I could give it a loop of 3 or 7 or 10 or so and it would just go from tab to tab. I never use it to open a new tabs, only on ones that are already open. But now when I run it, it stalls out after it loops once. It seems like its still counting relationally from the very first tab.

“Commands”: [
{
“Command”: “bringBrowserToForeground”,
“Target”: “”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “clickAndWait”,
“Target”: “name=take_ownership”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “check”,
“Target”: “name=j_id0:frm:j_id28”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “id=j_id0:frm:j_id35”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “selectWindow”,
“Target”: “tab=1”,
“Value”: “”,
“Description”: “”
}
]
}

I found this in a thread from 2018:

  "Command": "selectWindow",
  "Target": "tab=${!LOOP}",
  "Value": "",
  "Description": ""

This works for one tab at a time doesn’t let me do things like tell it to skip 2 tabs for each loop.

I hope that helps to explain what im trying to do.

Can you create a test macro that we can run from here? our macro looks ok, but without a test case that we can run, it it is difficult to say what goes wrong.

So I run these scripts from already open tabs, none of them open tabs so for this example you will need to open 4 new tabs. For ease of use, here are some examples:

Automate Browser Tabs - Ui.Vision RPA and Selenium IDE - Test Page
selectWindow, select Window - Selenium IDE Commands Tutorial
*1* TAB1
*2* TAB2

Once you have those loaded, go to the leftmost one and run this script with a loop of 4

{
  "Name": "loop error demo",
  "CreationDate": "2024-7-31",
  "Commands": [
    {
      "Command": "echo",
      "Target": "${!LOOP}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=1",
      "Value": "",
      "Description": ""
    }
  ]
}

While the loop will continue for all 4 plays, it does not go past the second tab.

I slightly modified the macro above and used the links in the order listed.
Script:

{
  "Name": "loop error demo",
  "CreationDate": "2024-7-31",
  "Commands": [
    {
      "Command": "storeTitle",
      "Target": "",
      "Value": "mytitle",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${mytitle}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=1",
      "Value": "",
      "Description": ""
    }
  ]
}

And this is the log output:

    [status]

    Playing macro loop error demo

    [info]

    Executing:  | storeTitle |  | mytitle | 

    [info]

    Executing:  | echo | ${mytitle} |  | 

    [echo]

    selectWindow, select Window - Selenium IDE Commands Tutorial

    [info]

    Executing:  | selectWindow | tab=1 |  | 

    [status]

    Current loop: 2

    [info]

    Executing:  | storeTitle |  | mytitle | 

    [info]

    Executing:  | echo | ${mytitle} |  | 

    [echo]

    Automate Browser Tabs - Ui.Vision RPA and Selenium IDE - Test Page

    [info]

    Executing:  | selectWindow | tab=1 |  | 

    [status]

    Current loop: 3

    [info]

    Executing:  | storeTitle |  | mytitle | 

    [info]

    Executing:  | echo | ${mytitle} |  | 

    [echo]

    Automate Browser Tabs - Ui.Vision RPA and Selenium IDE - Test Page

    [info]

    Executing:  | selectWindow | tab=1 |  | 

    [status]

    Current loop: 4

    [info]

    Executing:  | storeTitle |  | mytitle | 

    [info]

    Executing:  | echo | ${mytitle} |  | 

    [echo]

    Automate Browser Tabs - Ui.Vision RPA and Selenium IDE - Test Page

    [info]

    Executing:  | selectWindow | tab=1 |  | 

    [info]

    Macro completed (Runtime 5.40s)

Hi, thanks for the test case. I understand the question now.

selectWindow tab=1 only goes from the first tab, does not reassign a tab 0

Exactly! :slight_smile: But this works as designed: Tab=X is always the index of the tab relative to the start tab of the macro run (which is assigned tab=0). So when the macro opens a new tab, the index of the tabs remain constant, because they are defined by the tab in which the macro was started:

Here is a screenshot:

In this screenshot, I started the macro in the second tab of the browser, which is then tab=0.

The below macro will do what you want, and open all four tabs. I use TIMES to increase the index during each loop:

{
  "Name": "tabs1234",
  "CreationDate": "2024-8-2",
  "Commands": [
    {
      "Command": "storeTitle",
      "Target": "",
      "Value": "mytitle",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Start Tab = ${mytitle}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "times",
      "Target": "4",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=${!times}",
      "Value": "",
      "Description": "Switch to another tab"
    },
    {
      "Command": "storeTitle",
      "Target": "",
      "Value": "mytitle",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "t=${!times},  relative=${!current_tab_number_relative}, absolute=${!current_tab_number},${mytitle}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}
1 Like

Yes this does what I want it to do and additionally allows me to add a prompt to specify the amount when I start the script. Which I have wanted forever :slight_smile: .

Is there a way to express times with a modifier, like $!times*2 or $!times+2 to make it skip 2 or 3 tabs at a time?

Nevermind, fixed it with executeScript_Sandbox, if there’s a simpler way I am all ears however.

    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${!times}) + Number (2)",
      "Value": "next",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${next}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "selectWindow",
      "Target": "tab=${next}",
      "Value": "",
      "Description": ""
    },

Finished product, for anyone looking at this later.

{
  "Name": "completed task",
  "CreationDate": "2024-8-2",
  "Commands": [
    {
      "Command": "store",
      "Target": "1",
      "Value": "default",
      "Description": ""
    },
    {
      "Command": "prompt",
      "Target": "How many loops?@${default}",
      "Value": "amount",
      "Description": "How many times?"
    },
    {
      "Command": "times",
      "Target": "${amount}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "name=edit",
      "Value": "",
      "Description": "edit task"
    },
    {
      "Command": "select",
      "Target": "id=tsk12",
      "Value": "label=Completed",
      "Description": "task status"
    },
    {
      "Command": "clickAndWait",
      "Target": "name=save",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${!times}) + Number (2)",
      "Value": "next",
      "Description": "MATH"
    },
    {
      "Command": "selectWindow",
      "Target": "tab=${next}",
      "Value": "",
      "Description": "Switch to another tab"
    }
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}
1 Like

Perfect. Just to confirm: executeScript_Sandbox is the best way to make these calculations/increments/decrements.

1 Like