I have the following AppleScript with Javascript contained:
set buttontext to "Add Option"
set buttonloc to 1
tell application "Safari"
activate
tell window 1
do JavaScript "var buttonTags = document.getElementsByTagName(\"button\");
var searchText = \"" & buttontext & "\";
var found;
for (var i = 0; i < buttonTags.length; i++)
{if (buttonTags[i].textContent == searchText) {
found = buttonTags[i]; break;
}
}
buttonTags[" & buttonloc & "].click();"
end tell
end tell
It compiles fine but upon execution there is no action and I receive a 'missing value' error. It is designed to traverse a web page in Safari and allow a user to specify the button text and rank to be able to click it.
When execute this Javascript directly in Safari's dev console it works, but I need to have it in AppleScript to wrap it into a longer routine.
Advice appreciated!