tell application "Google Chrome" set myVar to execute Javascript "document.getElementsByTagName('input')" log "did it" log myVar end tell
-
The result of your javascript is a complex type, and if you can update it to return a scalar value, Would be weird to try and return a JSON object to Applescript. I can give you a code snippet to make it work for scalar value.user3579815– user35798152021-03-04 12:53:09 +00:00Commented Mar 4, 2021 at 12:53
-
I am trying to get a list of all the input elements on a webpage. Is there anyway I can do that with AppleScript? Perhaps parse the JSON?Kiyana Dunlock– Kiyana Dunlock2021-03-04 15:22:24 +00:00Commented Mar 4, 2021 at 15:22
-
You could probably serialize the JSON object into a string, pass it back to AppleScript, then deserialize it into an array of records.user3579815– user35798152021-03-05 00:08:39 +00:00Commented Mar 5, 2021 at 0:08
Add a comment
|
1 Answer
As mentioned, if you could replace the result with a scalar value, like read an attribute or value of an HTML element, you could do:
tell application "Google Chrome"
set myVar to execute tab 1 of window 1 javascript "1"
log "did it"
log myVar
end tell
For simplicity, it is just returning the 1 literal. You can change the javascript code that returns a scalar value like: document.getElementById('someId').value