Select the last item option on a menu

@admin @Plankton @ulrich

I need to select the last item of a menu not knowing how many items are in a menu.

Is there a command to select the last item in an option menu?

Url to test

My macro code

{
  "Name": "Select",
  "CreationDate": "2020-12-19",
  "Commands": [
    {
      "Command": "select",
      "Target": "xpath=//*[@id=\"section-select-with-label\"]/section/div/select",
      "Value": "index=0"
    }
  ]
}

With index=0 i can select the first element but how i can select the last option (you must remember I do not know the number of option in select).

It exist a solution to count the option in select ?

It exist a command to select the last option in select ?

Thanks for suggestion

To count the element in menu i found this

Need conversion for ExecuteScript

Thanks

Do you know the label? If so, you could use: select | xpath | label=

This also jumps to the end of the list: Xtype | ${KEY_PGDN}

I prefer not to use xtype for 3 reasons

  1. xtype requires focus on the screen so I can’t work with multiple browsers at the same time

  2. xtype requires to have xmodules installed and I do not have the possibility to install it in some machines

  3. xtype for free users allows a maximum of 25 commands for every macro/testcase.

For all these reasons I create macros using standard selenium commands that are unlimited and do not require screen focus so I can start multiple browsers that work together.

You can start with a “too high” index and then reduce the index until !statusOK is true. Demo:

{
  "Name": "Select LAST entry",
  "CreationDate": "2020-12-23",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ui.vision/contact",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "!TIMEOUT_WAIT"
    },
    {
      "Command": "comment",
      "Target": "i is the MAX. expected number of entries",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "10",
      "Value": "i"
    },
    {
      "Command": "do",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusok"
    },
    {
      "Command": "select",
      "Target": "id=WhatSoftware",
      "Value": "index=${i}"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${i}) - 1;",
      "Value": "i"
    },
    {
      "Command": "repeatIf",
      "Target": "${!statusOk} == false",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Done! Selected LAST index = ${i}",
      "Value": "blue"
    }
  ]
}
2 Likes

Working great, thanks