Writing a Browser Text Field to a Variable and Clipboard

Hi,
I am new to this awesome new world of Applescript. I am writing a script that takes me to a web page using Chrome and then then grabs a read only field containing a value. I can’t find how I can write that value that I get via javascript into the clipboard so I can use it in another step in the script.

Here is an example where I tried to set v = result of the value of P15_ENVIRONMENT_AAI_PASSWORD. The dialog just says msng so I am definitely not doing this correctly. I am not much of a programmer and just hacking my way through this. I could find plenty of examples of how to execute javascript through applescript but nothing where I can set the value from the script to a applescript variable.
Thanks!!

tell application “Google Chrome”
activate
open location “https://demo.xxxx.com/apex/f?p=355:15:108494447248756::NO::P15_INSTANCE_NAME:” & (text returned of theResponse)
delay 7

end tell

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)
–execute javascript “document.querySelectorAll(‘.tile-grid .most-visited’)[3].click()”
end tell

Hey Pius,

(I should add a disclaimer - I’m also fairly new to Applescript!)

‘set the clipboard to v’ is the correct way to set the clipboard to the value of a variable.
If you aren’t seeing the value you expect, it might be an issue with your javascript.

If you are not seeing the data you are expecting in the clipboard, you can try adding ‘return v’ in the script. This will stop the script running and return whatever the variable is at that stage.
for example, I added it to your code below.

I just finished a small project that meant that I needed to manipulate web pages, and I found a very useful set of tutorials. This one specifically might have the info you need:
http://www.cubemg.com/how-to-extract-information-from-a-website-using-applescript/

Hope it helps!


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
	
	return v
	
	display dialog (v)
	--execute javascript "document.querySelectorAll('.tile-grid .most-visited')[3].click()"
end tell