Last active
August 28, 2023 21:18
-
-
Save aevans-mms/ec091dd430809f0907ed8916329cec04 to your computer and use it in GitHub Desktop.
This file contains 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
// parse_options.js | |
function parse_options(locator) { | |
let options = []; | |
document.querySelectorAll(locator).forEach(option => { | |
console.log(option); | |
const value = option.getAttribute("value"); | |
const text = option.text; | |
const key = text | |
.replaceAll(" ", "_") | |
.replaceAll(",", "_") | |
.replaceAll("-", "_") | |
.replaceAll("'", "_") | |
.replaceAll("/", "_") | |
.replaceAll("’", "_") | |
.replaceAll(".", "") | |
.replaceAll("(", "") | |
.replaceAll(")", "") | |
.replaceAll("&", "AND") | |
.toUpperCase(); | |
options.push({ | |
option: option, | |
key: key, | |
value: value, | |
text: text, | |
}); | |
}); | |
return options; | |
} | |
let locator = "select#country > option"; // <== change locator for each dropdown | |
const options = parse_options(locator); | |
let data = ""; | |
options.forEach(option => { data += `${option.key}("${option.value}", "${option.text}")` + "," + "\n"}); | |
console.log(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment