Created
August 14, 2020 05:58
-
-
Save seleniumgists/334be711f2ac1ba14e63cf160ff8c559 to your computer and use it in GitHub Desktop.
generated automatically from #selenium on seleniumhq slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The id of the checkbox we intend to click. | |
final String checkboxIdToClick = new String("363171428_2399318203") | |
// Check values of the map for a webelement that has a matching id attribute. | |
getCheckboxMap().forEach((k,v) -> { | |
// If the value's attribute matches expected id, then the key webelement should be clicked since the child cannot. | |
if(v.getAttribute("id").equals(checkboxIdToClick) k.click() | |
}); | |
private Map<WebElement,WebElement> getCheckboxMap() { | |
// Strings to hold css targets. | |
final String containerCss = new String("div.checkbox-container"); | |
final String checkboxCss = new String(containerCss + " input"); | |
// Create invidual lists of parent and child input elements. | |
List<WebElement> elementContainers = driver.findElements(containerCss); | |
List<WebElement> checkboxElements = driver.findElements(checkboxCss); | |
// make sure the lists are the same size before iterating. | |
if(elementContainers.size() == checkboxElements.size()){ | |
final Map map = new Map(); | |
// Iterate through both lists and add them to a map. | |
// Key = parent div element. | |
// Value = child input element. | |
for(int i = 0; i < elementContainers.size(); i++){ | |
map.put(elementContainers.get(i),checkboxElements.get(i)); | |
} | |
return map; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment