java - selenium filter with Predicate -
i looking use , learn predicate , lambda expression. in particular using selenium.
imagine have large selection(list) of webelements , want apply predicate filter list smaller .
am on right track 1,2,3 below changes meed make?
list<webelement> webelements = driver.findelements(by.cssselector(".someclassname")); // returns large list // try , filter down list predicate<webelement> hasredclass -> predicate.getattribute("class").contains("red-background"); predicate<webelement> hasdatatoggleattr -> predicate.getattribute("data-toggle").size() > 0; // without predicate looks //driver.findelements(by.cssselector(".someclassname .red-background")); // 1. think should like??? list<webelement> webelementswithclass = webelements.filter(hasredclass); // 2. hasdatatoggleattr list<webelement> webelementswithdatatoggleattr = webelements.filter(hasdatatoggleattr); // 3. both of them together... list<webelement> webelementswithbothpredicates = webelements.filter(hasredclass, hasdatatoggleattr);
i hope here looking for:
list<webelement> webelements = driver.findelements(by.cssselector(".someclassname")); // returns large list // try , filter down list predicate<webelement> hasredclass = -> we.getattribute("class").contains("red-background"); predicate<webelement> hasdatatoggleattr = -> we.getattribute("data-toggle").length() > 0; // without predicate looks //driver.findelements(by.cssselector(".someclassname .red-background")); // 1. think should like??? list<webelement> webelementswithclass = webelements.stream() .filter(hasredclass).collect(collectors.tolist()); // 2. hasdatatoggleattr list<webelement> webelementswithdatatoggleattr = webelements.stream() .filter(hasdatatoggleattr).collect(collectors.tolist()); // 3. both of them together... list<webelement> webelementswithbothpredicates = webelements.stream() .filter(hasdatatoggleattr.and(hasredclass)).collect(collectors.tolist());
Comments
Post a Comment