Select random value in the Weblist

In the previous post, we have seen how to work with check boxes and radio button in selenium.In this post, we will see how to Select random value in the Weblist.

In any scenario, if there is a requirement that you need to test the functionality with different data. If you have a WebList in you application , then instead of passing data from any source you can instruct the code to select a random value in the WebList each time you run the code.

For generating the random value, We will use class ‘Random’ and instruct it to generate the number between 0 to 4. Because in our demo application, We have 5 values in our WebList.

Random random = new Random();
int index = random.nextInt(5); // It will give a range between 0 to 4

Code for selecting the random value in a weblist:

Now, every time you run the code, it will select a different value into the weblist.


Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Working with CheckBoxes and Radio Buttons
Enter text in a edit box and click on a button
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *