Skip to content

Instantly share code, notes, and snippets.

@Yatoom
Last active November 5, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yatoom/c3bc3929bd9ead99b9cbc7dfeb62fddd to your computer and use it in GitHub Desktop.
Save Yatoom/c3bc3929bd9ead99b9cbc7dfeb62fddd to your computer and use it in GitHub Desktop.
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