I’m trying to select an option from a category dropdown through a chrome extension with javascript and jquery. When I normally select an option from the first dropdown menu, the values ??in the second dropdown menu change based on my selection.
I tried to select an option with many different methods, here are most of them:
in jquery
$("#categorisation_1").val($("#categorisation_1 option").eq(4).val());
$('#categorisation_1').val('5: Object').change();
$('#categorisation_1').val('5: Object').dblclick();
$('#categorisation_1>option:eq(5)').prop('selected', true);
$("#categorisation_1").val('5: Object').trigger('change');
$('#categorisation_1').val('2: Object');
$('#categorisation_1>option:eq(5)').attr('selected', 'selected').trigger('change');
$('#categorisation_1').find('option:eq(3)').attr('selected', true);
in javascript
document.getElementById('categorisation_1').options[3].selected=true;
document.getElementById('categorisation_1').value = '9: Object';
document.getElementById("categorisation_1").selectedIndex = 1;
document.getElementById('categorisation_1').getElementsByTagName('option')[10].selected = 'selected';
document.getElementById('categorisation_1').value = '9: Object';
document.getElementById('categorisation_1').focus();
document.getElementById('categorisation_1').value = '5: Object';
document.getElementById("categorisation_1").options[2].selected = "selected";
document.getElementById('categorisation_1').getElementsByTagName('option')[5].selected = 'selected'
*******************
var select = document.getElementById("categorisation_1");
select.size = select.options.length;
******
document.getElementById('categorisation_1').setAttribute('size', 3);
********************
Array.from(document.getElementById('categorisation_1').options)
.filter(x => x.value === "9: Object")[0]
.setAttribute('selected', true);
Nothing worked… They change the value in the category dropdown but it doesn’t trigger the changes in the next dropdown. Is there a way to select an option as if I was human, via javascript or Simulate pressing a button on the keyboard or any other method?
here is the source code of the first drop down menu
enter image description here
2
Answers
here is the answer if it can help anyone else thanks @Snm