Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Writing a Browser Text Field to a Variable and Clipboard

Hi,

We have an internal system where it stores a value in a read only text field. I want to copy that value into a variable or the clipboard and then reuse it somewhere else.


I tried to find any doc that shows you how to to get a value from javascript and make it a applescript variable. My incorrect code just sets my v to the exec javascript text. I want to get the value from the ElementId P15_ENVIRONMENT_AAI_PASSWORD. Thanks!



tell application "Google Chrome" to tell active tab of window 1

set v to execute javascript "document.getElementById('P15_ENVIRONMENT_AAI_PASSWORD').value"

set the clipboard to v

display dialog (v)

end tell

MacBook Pro (Retina, 13-inch, Late 2013)

Posted on Dec 13, 2017 10:44 AM

Reply
Question marked as Best reply

Posted on Dec 14, 2017 12:24 PM

Given the following simplistic HTML, opened in a Google Chrome Version 63.0.3239.84 (Official Build) (64-bit):


User uploaded file


The following AppleScript works:


tell application "Google Chrome" to tell active tab of window 1

set v to (execute javascript "document.getElementById(\"P15_ENVIRONMENT_AAI_PASSWORD\").innerText;") as text

end tell

logv

set the clipboard tov

set x to (the clipboard)

display dialog ("v: " & v as text) & return & "x: " & x as text

return


User uploaded file

2 replies
Question marked as Best reply

Dec 14, 2017 12:24 PM in response to Pius Kid

Given the following simplistic HTML, opened in a Google Chrome Version 63.0.3239.84 (Official Build) (64-bit):


User uploaded file


The following AppleScript works:


tell application "Google Chrome" to tell active tab of window 1

set v to (execute javascript "document.getElementById(\"P15_ENVIRONMENT_AAI_PASSWORD\").innerText;") as text

end tell

logv

set the clipboard tov

set x to (the clipboard)

display dialog ("v: " & v as text) & return & "x: " & x as text

return


User uploaded file

Writing a Browser Text Field to a Variable and Clipboard

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.