Skip to content

Instantly share code, notes, and snippets.

@kaldaf
Created March 6, 2024 13:18
Show Gist options
  • Select an option

  • Save kaldaf/5b5a993d9f30046bc1d6771dcaa3c341 to your computer and use it in GitHub Desktop.

Select an option

Save kaldaf/5b5a993d9f30046bc1d6771dcaa3c341 to your computer and use it in GitHub Desktop.
office form autofill
// Autofill checkboxes + radio buttons
const questions = document.querySelectorAll('[data-automation-id="questionItem"]');
questions.forEach((question) => {
const options = question.querySelectorAll('[data-automation-id="choiceItem"]');
let isRadio = question.innerHTML.includes('radiogroup');
if (isRadio) {
const randomIndex = Math.floor(Math.random() * options.length);
options[randomIndex].querySelector('input').click();
} else {
const randomAmount = Math.floor(Math.random() * options.length) + 1;
const randomIndexes = Array.from({ length: randomAmount }, (_, i) => i);
randomIndexes.forEach((index) => {
options[index].querySelector('input').click();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment