Can we select a random div?

Hi.
I have a list of 59 items (called trades) on a page and all have a radio button to allow Multi-selection.
I can select a name of an item (trade) which will select the radio button for the item.

The item (trade) I am looking to select is in a div called “trade-block-item” (class) which will select the radio button when I select the div:

> <div class="trade-block-item" data-bind="css: { 'margin-bottom-20': $index() + 1 === $parent.items.length }, attr: { 'id': 'trade-type-' + SystemName }" id="trade-type-Roofer">
>               <div class="trade-block-checkbox">
>                 <input type="checkbox" class="round" name="tradetypes" data-bind="attr: { 'id': 'checkbox' + Id}, click: $root.select.bind($root, $data), checked: $root.isSelected($data.Id)" id="checkbox799207">
>                 <label data-bind="attr: { 'for': 'checkbox' + Id }" for="checkbox799207"></label>
>               </div>
>               <div class="trade-block-name clickable" data-bind="text: Name, click: $root.select.bind($root, $data)">Roofer</div>
>             </div>

With there being 59 items (trades), is that a way in which I can randomly select an item (trade) instead of always selecting the same item (trade)?

Think i’ve achieved this now through:

  • Adding the list of items to a CSV file and getting a random value (Get random value from a CSV file action)
  • Passing the random value (Output) into a Parameter (called it RandomTradeType)
  • Parameter added to the XPath for the Element (Generic web element)

Example:
//*[@id=“trade-type-{RandomTradeType}”]/div[2]

Item for the Random value returned from the CSV now selected

another way to do this is by counting first the number of div (using count element), and use this as the maximum # in Get Random value.

1 Like

Thanks, much appreciated :slightly_smiling_face: