0

I have a page that contains 10 drop down options and each drop down has a list of values. I would like for Selenium to run the script, select a random drop down and then a random value within that drop down. Does anyone have any insight on to how to get a random value selected?

Currently I have the code setup to select the first drop down that is available then select the first value within that list. The code looks like this:

// Selects the first drop down
selenium.click("css=div.dropdown"); 
// Selected the first value in the first drop down
selenium.click("css=td.dijitMenuItemLabel"); 

Any help would be great!

2 Answers 2

4

This is the code to select a random dropdown value

String []options = selenium.getSelectOptions("locator");
int index = (int)( Math.random() * options.length);
selenium.select("locator" , "index="+index);

Regarding dropdown, you can store their locators in an array and select the random value

Sign up to request clarification or add additional context in comments.

Comments

1

try this

long number = (long) Math.floor(Math.random() * 900L) + 100L;

System.out.println(""+number);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.