18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Random listbox

arunbalaarunbala Members
edited November -1 in Sahi - Open Source
Hi,
Am having a list box contains some values. While executing the scripts i wants to select a value randomly. Is there any methods available for it?

Thnx

Comments

  • globalwormingglobalworming Moderators
    edited March 2012
    Hi,

    you can use the _collect api and http://lmgtfy.com/?q=javascript+random

    Regards
    Wormi
  • Hi Wormi,
    I didnt get this link. pls look into that
  • globalwormingglobalworming Moderators
    edited March 2012
    The link is working fine, what I am trying to tell you with this link might not be clear.
    For going a little bit deeper into this: Think about what elements should be accessed randomly, then use the _collect API to store these elements in an array. Then create your random index with Math.random like it has been done here
    function getRandom(min, max) {
     if(min > max) {
      return -1;
     }
     
     if(min == max) {
      return min;
     }
     
     var r;
     
     do {
      r = Math.random();
     }
     while(r == 1.0);
     
     return min + parseInt(r * (max-min+1));
    }
    
    (source: http://www.naden.de/blog/zufallszahlen-in-javascript-mit-mathrandom)

    Regards
    Wormi
Sign In or Register to comment.