I've been searching restlessly for a way to automatically select a survey form button that contains a specific word. I am using Tampermonkey in Google Chrome. In this case, I would like to automatically select buttons with the word 'Male' in them.
Here is an example of the type of button I am talking about (including CSS/HTML):
So for the question: "What is your gender?", I would like to automatically select 'Male.' I have been running through all of the stackoverflow questions I can find that could possibly help, but with no results. I chose a label-based method and used "textContent" to hopefully be able to recognize the text within the form question.
Here is the code I am currently working with (from How can I auto-select a radio button with Greasemonkey?):
// ==UserScript==
// @name Button Text Form Filler
// @include https://tasupport.co1.qualtrics.com/jfe/form/SV_0qez6NHJGoCAmMt
// @version 1.0
// @description Demonstration script to change form values
// ==/UserScript==
var labels = document.getElementsByTagName('label');
for (var i = 0; i < labels.length; ++i) {
if (labels[i].textContent == "Male") {
labels[i].click();
}
}
Unfortunately, the code doesn't work and the button for 'Male' is not selected on page load. This can be tested in the 2nd page of the following website: https://tasupport.co1.qualtrics.com/jfe/form/SV_0qez6NHJGoCAmMt (where the above screenshot comes from).
I have also tried the following with jQuery (How do I automatically click this button with tampermonkey?):
// ==UserScript==
// @name jQuery Button Test
// @version 0.1
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @include https://tasupport.co1.qualtrics.com/jfe/form/SV_0qez6NHJGoCAmMt
// ==/UserScript==
$(document).ready(function() {
$("button:contains('Male')").click();
});
Again, nothing.
There are a few similar questions to mine scattered across stackoverflow, but none of the solutions appear to work here, or perhaps the code I am working with is outdated. I would appreciate any and all help. Thanks in advance.