I am using Snippets in the developer tools of a Chromium based web browser (Edge). I am trying to fill out a select box on a form from a website. The issue is that the select box options are dynamically created and are based on a selection from another select box. Every time the 'parent' selection is made the page refreshes and populates the new options for the second select box.
Here is a function that I used to set the first select box, however it doesn't work on the second one. I think it has something to do with when the page refreshes but I am not sure.
//Find value by entered text
function selectElement(selectorType, selector, text) {
var e = document.getElementById(selector);
//find value of text
for (var i = 0; i < e.options.length; i++) {
if (e.options[i].text === text) {
e.selectedIndex = i;
break;
}
}
if (selectorType == "id") {
jqSelector = '#'+selector;
$(jqSelector).val(e.value).change();
}
console.log(jqSelector, e.value);
}
selectElement('id', 'mySelector', "My Text");