Quality Testing

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

Views: 53

Replies to This Discussion

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());

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service