ARTICLE AD BOX
I have a web app that I use with a process that often fails, resulting in a button being rendered to 'retry'. Often it takes several clicks (with a few minutes of waiting in between) of the retry button before the process succeeds.
I am trying to make an AppleScript that when executed will loop through the active page and whenever it finds that retry button, click it. There could be many instances of the retry button.
The button has no identifier or class that separates it from other buttons on the page, other than the data-cy attribute: data-cy="retry-failed-creation-button" .
Here is the button HTML in full:
<button type="button" class="text-2xs h-8 w-full rounded-md px-2 font-medium tracking-wide bg-neutral-50 text-neutral-900 cursor-pointer !rounded-r-none !h-6" data-cy="retry-failed-creation-button">Retry</button>I have tried the following AppleScript, but I get an end of line expected error in the JS console in Safari when running. The error happens at the first hyphen in retry-failed-creation-button . I tried escaping the hyphens but no difference.
on run tell application "Safari" activate delay 1 do JavaScript "var buttons = document.querySelectorAll('[data-cy='retry-failed-creation-button']'); for (i = 0; i < buttons.length; i++) { buttons[i].click(); }" in front document end tell end runWhat am I doing wrong?
To note: I cannot change the HTML code of the web app. I cannot use JQuery.
Edit: I suppose my main problem is, how do I grab all the instances of the buttons with the data-cy attribute with the value retry-failed-creation-button. My document.querySelectorAll('[data-cy='retry-failed-creation-button']') line is not working. Do I have a syntax error, or an escaping the special characters issue?
