I'm using some script which basically get text from safari, click button and fill up textfield.
e.g :
tell application "Safari"
set texttograb to do JavaScript "document.getElementsByClassName('the_variable_as_text')[0].value;" in document 1
do JavaScript "document.getElementsByClassName('text-entry')[0].value=" & quoted form of myText in last tab of window 1
do JavaScript "document.getElementsByClassName('Approve-button')[0].click();" in last tab of window 1
end tell
This work perfectly but I have a change in my workflow and I need to use different safari window.
How can I refer one javascript to one specific safari window and the other to a different window.
Especially when some tab might have the same URL/Name ?
I remember seeing that a while back (when the tab happen to have the same name but I never manage to run a script which refer to the window id
Otherwise I suppose I can use another web browser (e.g one safari the second safari technology preview) as a workaround but that not really ideal and limit to two windows
any idea how can I found the window ID and refer to it in AppleScript/JS ?
Best Answer
It's not the best (won't work if the same tab is open in different windows) but This seems to work
then I can refer the window using theWindowID
e.g:
or
(I'm referring the tab manually)