Created
March 6, 2024 13:18
-
-
Save kaldaf/5b5a993d9f30046bc1d6771dcaa3c341 to your computer and use it in GitHub Desktop.
office form autofill
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
| // 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