Reputation: 3
I'm trying to select radio buttons randomly on a google form. I tried browsing the web for a working script but none of them are working. I tried to make my own but I'm always getting that error:
Cannot read property 'click' of undefined.
Firstly I do a:
document.querySelectorAll('.freebirdFormviewerViewNumberedItemContainer');
to get all parts of the form. It returns the correct amount of parts. Then I do an
item.querySelectorAll(".appsMaterialWizToggleRadiogroupOffRadio");
to get all of the radio buttons in that part and it returns the correct amount of radio buttons.
After that I randomly pick one and perform .click()
on it but it gives me that error. Even if I querySelect anything else it's still doesn't works.
Any idea how to fix that or google made it impossible to manipulate it's forms?
Upvotes: 0
Views: 879
Reputation: 1608
Just looking at the underlying HTML of the radio buttons in a google form, I was able to isolate each of the radio buttons using all these classes together, so:
var allRadioButtons = document.querySelectorAll(".appsMaterialWizToggleRadiogroupElContainer.exportContainerEl.docssharedWizToggleLabeledControl.freebirdThemedRadio.freebirdThemedRadioDarkerDisabled");
var numberOfRadioButtons = allRadioButtons.length;
function randomNumber(min, max) {
return Math.floor((Math.random() * max) + min);
}
var randomRadioButtonNumberToSelect = randomNumber(0, numberOfRadioButtons);
allRadioButtons[randomRadioButtonNumberToSelect].click();
works for me.
This of course only works for one question in a google form, you would have to do some more manipulation to work with multiple questions, I would suggest first finding an array of questions, and then for each question selecting the radio buttons that are a child of that question at random, and then moving on to the next question
Upvotes: 1