w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Selenium WebDriver how to select a random option from select option menu excluding one option

add couple of lines of code to define a range

Random randomOption = new Random();       
int startOption = 1; //assuming "--your choice--" is index "0"
int endOption = user_country.getOptions().size()); // end of range  

int number = startOption + randomOption .nextInt( endOption - startOption);
 

//then do your stuff

Select kraj = new Select (driver.findElement(By.id("kraj")));
kraj.selectByIndex(number );




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.