I'm trying to make a script that types some random data in a form but on the page i also have the options to select the gender: Male / Female, each gender is in a radion button (different id's/xpath etc) how can i make the button selection random?. Lets say button Male has id = 12 and button female has id = 23 How can i make it select 12 or 23 or xpath 1 vs xpath2
Asked
Active
Viewed 394 times
-1
-
Do you want a c# code for it ? do you want to select random male or female for radio button in C#? – Ahmad Mar 28 '18 at 20:08
-
1Possible duplicate of [How do I generate a random int number in C#?](https://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c) – JeffC Mar 28 '18 at 20:50
-
I can go with what Miguel said, i know how to write that in C#. Thanks – Banu Mar 29 '18 at 06:52
1 Answers
0
you can generate a random 0 or 1 where if it is 0 select man, if it is 1 woman, for example:
JAVA
Random
int max = 1
int min = 0
int num = random.nextInt(max - min + 1) + min
if(num == 1){
driver.findElement(By.Xpath("/WOMEN"))
}else{
driver.findElement(By.Xpath("/MEN"))
}
OR
in your xpath:
public By womenOrMen(value){
return By.Xpath("//div/div/div/span[1]/input[@id='"+ value +"']");
}

Miguel D'Alessio
- 116
- 12