0

tell application "Google Chrome" set myVar to execute Javascript "document.getElementsByTagName('input')" log "did it" log myVar end tell

3
  • 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. Commented 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? Commented 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. Commented Mar 5, 2021 at 0:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.