Problem:
Applescript errors when executing a javascript in Safari.
Javascript:
document.getElementById(“ap1_header_lblPendingRxCount”).innerText
When executed in Safari’s javascript console, the javascript executes successfully and returns an integer as text, reflecting the count of pending rx.
When compiled in Applescript, the javascript looks like this.
Applescript:
tell application "Safari"
set js to "document.getElementById(\"ap1_header_lblPendingRxCount\").innerText"
set PendingRxCount to do JavaScript js in document 1
end tell
When executed in AppleScript, Safari’s Javascript console returns a “null is not an object” error:
Console error:
TypeError: null is not an object (evaluating ‘document.getElementById(“ap1_header_lblPendingRxCount”).innerText’)
Question:
How can I correct this Applescript to have it successfully execute this javascript?