Using Watir-Webdriver, how can I automate the output of all the elements in an array in a totally random order

StackOverflow https://stackoverflow.com/questions/9328373

  •  27-10-2019
  •  | 
  •  

Question

Using Watir-Webdriver, how can I automate the output of all the elements in an array in a totally random order. My array has 9 items which are pulled from a CMS and the items are pulled into a list which is numbered 1,2,3,4,.... but in a complete random order each time.

Unfortunately I do not have an example or screenshot to share and do not expect a full solution to my issue. If someone can just point me in the right direction, I would be very grateful.

Was it helpful?

Solution

This is really more of a Ruby question that Watir-webdriver. Speaking purely to the question as answered (which frankly I think is masking a larger challenge you are facing) I would do the following

1) shuffle the array. the .shuffle method has been built in from at least ruby 1.8.7 onward.
2) then use either .each or .each_with_index to traverse the now randomized array

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top