Last active
November 5, 2016 21:26
-
-
Save Yatoom/c3bc3929bd9ead99b9cbc7dfeb62fddd to your computer and use it in GitHub Desktop.
This file contains 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
function randomIndex(list) { | |
return Math.floor(Math.random() * list.length) - 1 | |
} | |
function triggerUpdate(el) { | |
el.click() | |
el.dispatchEvent(new Event('change')); | |
} | |
function fillRandom() { | |
// Click on each second button or something, except previous button and next button | |
// Could be improved | |
document.querySelectorAll("input:not(#PreviousButton):not(#NextButton)").forEach(function(e, i) { | |
if (i % 2 == 0) { | |
e.click() | |
} | |
}) | |
// Fill in random strings in text fields | |
document.querySelectorAll("input[type=text]").forEach(function(e,i) { | |
if (e.id.includes("QID170") || e.id.includes("QID58")) { | |
return | |
} | |
e.value = Math.random().toString(36).substring(7); | |
triggerUpdate(e) | |
}) | |
// Select random stuff from dropdowns | |
document.querySelectorAll("select").forEach(function(e,i) { | |
// select random, but skip first one (because that one is empty) | |
e.selectedIndex = 1 + randomIndex(e.options) | |
triggerUpdate(e) | |
}) | |
// Fill in some stuff that you have to fill in correctly | |
try { | |
var field = document.querySelector("[id^='QR'][id$='QID170']") | |
field.value = 18 + Math.floor(Math.random() * 20) | |
triggerUpdate(field) | |
} catch(e) {} | |
try { | |
var field = document.querySelector("[id^='QR'][id$='QID58']") | |
field.value = Math.floor(Math.random() * 20) | |
triggerUpdate(field) | |
} catch(e) {} | |
// Click next button | |
document.querySelector("#NextButton").click() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment