Q:

How to select element from drop down Randomly in Selenium webdriver (java) drop down is in html?

I want to select random manufactures of the vehicle.The problem is i couldn't find a way to randomly select element.every time i have to give vehicle Name through sendkeys().
Below is the html code where i am finding drop down of vehicle manufacture by id & all the element which i want to select randomly.
  <select name="vehicleManufacturerId" id="vehicleManufacturerId" size="1" 
  style="width: 250px; border: 1px solid rgb(117, 161, 208);" 
  onblur="backgroundChangeToOriginal(this),getfocus();" onchange="return 
  displayModelOnChangeManufacturer();" 
  onfocus="backgroundChangeOnFocus(this)">  
  <option value="Select">Select</option>

  <option value="1313-5">ALPHA ROMEO</option>

  <option value="1062-5">AUDI</option>

  <option value="1042-5">AUSTIN</option>

  <option value="1288-5">AUSTON MARTIN</option>

  <option value="1270-5">BENTLEY</option>

  <option value="1261-5">BMC</option>

  <option value="44-5">BMW</option>

  <option value="1156-5">CADILLAC</option>

  <option value="1363-5">CATERHAM</option>

  <option value="1263-5">CHAIRMAN</option>

  <option value="1023-5">CHANGAN</option>

  <option value="1230-5">CHARMANT</option>

  <option value="1051-5">CHERY</option>

  <option value="1021-5">CHEVERLET</option>

  <option value="1013-5">CHEVROLET</option>

  <option value="1292-5">CHRYSLER</option>

  <option value="1231-5">CITRIAN</option>

  <option value="1212-5">CITY </option>

  <option value="1258-5">COOPER</option>

  <option style="color:#F00" value="1385-5">DACIA (Expired)</option>

  <option value="1014-5">DAEWOO</option>

  <option value="65-5">DAIHATSU</option>

  <option value="1232-5">DAIHTSU </option>

  <option style="color:#F00" value="1369-5">DAIMLER  (Expired)</option>

  <option value="67-5">DATSUN</option>

  <option value="76-5">DODGE</option>

  <option value="1140-5">DONG </option>

  <option style="color:#F00" value="1336-5">FAIR LADY (Expired)</option>

  <option value="1031-5">FAW</option>

  <option value="1271-5">FERRARI</option>

  <option value="88-5">FIAT</option>

  <option value="91-5">FORD</option>

  <option value="1248-5">GEELY</option>

  <option value="1146-5">HAFEI </option>

  <option value="108-5">HONDA</option>

  <option value="112-5">HYUNDAI</option>

  <option value="1233-5">HYUNDAISANTRO</option>

  <option value="116-5">JAGUAR</option>

  <option value="1308-5">JOYNER</option>

  <option value="1015-5">KIA</option>

  <option value="1249-5">LANCER </option>

  <option value="1167-5">LAND </option>

  <option value="1293-5">LEXUS</option>

  <option value="1234-5">LIANA</option>

  <option value="1250-5">LIFAN</option>

  <option style="color:#F00" value="1390-5">LINCOLN (Expired)</option>

  <option value="1262-5">LOTUS</option>

  <option style="color:#F00" value="1317-5">MASERATI (Expired)</option>

  <option value="150-5">MASTER</option>

  <option value="153-5">MAZDA</option>

  <option style="color:#F00" value="157-5">MEHRAN (Expired)</option>

  <option value="1008-5">MERCEDES</option>

  <option style="color:#F00" value="1374-5">MG-B GT (Expired)</option>

  <option value="1307-5">MG-SPORTS</option>

  <option value="1254-5">MINI </option>

  <option value="1236-5">MITSB </option>

  <option value="1237-5">MITSU </option>

  <option value="1006-5">MITSUBISHI</option>

  <option value="1238-5">MITSUBISHITOWNY</option>

  <option value="1026-5">MORRIS</option>

  <option value="1009-5">NISSAN</option>

  <option value="1328-5">OLDSMOBILL</option>

  <option value="1012-5">OPEL</option>

  <option value="1284-5">PANORAMA</option>

  <option value="1239-5">PASSO</option>

  <option value="1241-5">PERODUA </option>

  <option value="181-5">PEUGEOT</option>

  <option value="1391-5">PLY</option>

  <option style="color:#F00" value="1354-5">PONTIAC (Expired)</option>

  <option value="1265-5">PORSCHE</option>

  <option value="1061-5">PROTON</option>

  <option value="1041-5">RENAULT</option>

  <option value="1049-5">REVO</option>

  <option value="1272-5">ROLLS </option>

  <option value="1246-5">ROVER</option>

  <option style="color:#F00" value="1304-5">SAAB (Expired)</option>

  <option value="1039-5">SKODA</option>

  <option style="color:#F00" value="1329-5">SKY WING (Expired)</option>

  <option value="1242-5">SMART</option>

  <option value="1153-5">SOGO </option>

  <option value="1038-5">SPECTRA</option>

  <option value="1268-5">SSANGYONG </option>

  <option style="color:#F00" value="1402-5">STUDIBAKER (Expired)</option>

  <option value="1011-5">SUBARU</option>

  <option value="1243-5">SUZK </option>

  <option value="246-5">SUZUKI</option>

  <option value="1154-5">TMC </option>

  <option value="255-5">TOYOTA</option>

  <option value="256-5">TRIUMPH</option>

  <option value="1407-5">UZBAA</option>

  <option value="1030-5">VAUXHALL</option>

  <option value="1259-5">VOLKS </option>

  <option value="1007-5">VOLKSWAGEN</option>

  <option value="1183-5">VOLVO</option>

  <option value="1257-5">VW </option>

  <option value="1244-5">WAGNOR</option>

  <option value="1335-5">ZOTYE</option>

    </select>

And here is the way i am adding vehicle manufacture in selenium 
   Select manufacturer_Id = new Select(driver.findElement(By.xpath(".//*
   [@id='vehicleManufacturerId']")));
      manufacturer_Id.selectByVisibleText("AUDI");

A:

You can simply provide a list of web elements and use Random class to get selenium select a random element from dropdown list. Here is the code snippet : 

Here I modified the script which you are using currently

List<WebElement> list = driver.findElements(By.xpath(".//*[@id='vehicleManufacturerId']//option"));
list.get(getRandomNumberInBetween(1, list.size() - 1)).click();

And here is the random method which I am going to use :

private static int getRandomNumberInBetween(int lowerBound, int upperBound) {
        Random r = new Random();
        return (r.nextInt(upperBound) + lowerBound);
    }

Hope this helped.

