Quality is delighting customers
Hi All,
How to print duplicate values in drop-down list using Java selenium.
I need code for this .
Thanks
Balaji
Tags:
If you're talking about HTML <select> tag
You can get all the optionsvalues into a List using //option XPath expression like:
List<String> allValues =
driver.findElements(By.xpath("//option"))
.stream()
.map(option -> option.getAttribute("value"))
.collect(Collectors.toList());
once done you can filter the all options values list and leave only duplicates using java.util.Stream API:
List<String> duplicateValues = allValues.stream().collect(Collectors.groupingBy(Function.identity()))
.entrySet()
.stream()
.filter(e -> e.getValue().size() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
© 2021 Created by Quality Testing.
Powered by