Turning on Bot Detection (reCAPTCHA) causes jQuery("#NextButton").click(); to stop working. | XM Community
Skip to main content

I have lots of JavaScript in my survey that does some work, sets some embedded data fields and then auto advances to the next question using  jQuery("#NextButton").click(); This all works great until I turn on Bot Detection using reCAPTCHA on my Survey Options. Then all of sudden my JavaScript clicks stop working. No errors are posted in the browser console.
I've tried this.clickNextButton() also with no success.
Any ideas?
Thanks!
-Dave

It is probably a timing issue (i.e., the next button isn't loaded when you are trying to click it). Two things:

  1. Try moving your script that clicks the next button from addOnload to addOnReady.

  2. When using this.clickNextButton() make sure 'this' refers to the question object (i.e., 'this' no longer refers to the question object inside another function). Assign 'this' to a variable at the top of the script, then use the variable (e.g.,
    var qobj = this;
    then later
     qobj.clickNextButton();
    )


Thanks TomG for your quick reply. Moving to addOnReady has no impact. And I've properly scoped the "this" variable.
It appears that Bot Detection disables the ability to auto advance, which makes sense if you're trying to foil a Bot. I can understand that.
Maybe there is another way to auto-advance that doesn't programmatically click the next button?
Here is a simplified code snippet that demonstrates my issue.
Qualtrics.SurveyEngine.addOnload(function()
{ });

Qualtrics.SurveyEngine.addOnReady(function()
{
var question = this;

setTimeout(function () {

//with Bot Detection enabled in Survey Options
//neither one of these work (no errors posted).
//Disable Bot Detection and either work fine.

question.clickNextButton();
//jQuery("#NextButton").click();

}, 500);

});

Qualtrics.SurveyEngine.addOnUnload(function()
{ });


I don't have the problem when using Bot Detection. Using this.clickNextButton() works fine (tested on Chromium and Firefox)




Nevermind. I just increased my timeout from 500ms to 1500ms and it works reliably now . You were right the first time, it was a timing issue. Seems like the Bot Detection adds some addition load time to the first question. 500ms delay was right on the edge.


I'm glad you solved it, but it is puzzling. I have no idea why I didn't have any issue with no setTimeout at all, and 1.5 seconds seems pretty long.


I agree something is odd here. Did you try this script on your first question? That seems to be the issue. Subsequent questions work fine.
My hunch is that there is additional loading when Bot Detection is enabled and the Next button for the first question is not ready for the click event. I've had it fail once or twice even with the 1.5 sec delay. I don't have a suitable workaround yet.
Is there any event that I can subscribe to when the button is ready? I've already moved my code to the addOnReady() event with no improvement.


You could use setInterval to continually look for the Next button until it is present.


The Next button is present and not disabled when I click it. I've checked that and the click event still does not register and advance to the next question. So that doesn't seem to solve it.
Final Solution: I set a boolean variable in the Qualtrics.SurveyEngine.addOnUnload() event and I use setInterval to keep clicking the next button until that boolean goes true. Seems to take at least 1000-1200 milliseconds before the click event unloads the question. This time is probably variable based on internet bandwidth of the respondent, so this fix should cover all cases.
Total hack! But works.
Thanks for your help.
-Dave


DaveW Hi buddy, i am facing similar problem with my code where jquery is working fine if Qualtrics fraud detection security i.e. Bot Detection using reCAPTCHA, Security scan monitor and RelevantID features are off but the moment I enable any of these features then my code stops running.

can you please let me know how you fix the issue?


Enabling Security Scan monitor prevented my survey from getting displayed in the correct language. They all went straight to English. Anyone else seen this behavior?

Thanks
-Mattias


Leave a Reply