Applescript javascript multiple line
-
21-04-2021 - |
Question
How can we add multiple line text in Chrome using document.getElementsByClassName? I have no issue when it's one line but one I have more than one I have a missing value instead
set myCaseNote to "MULTIPLE
LINE
TEXT
HERE"
tell application "Google Chrome"
tell tab 3 of window 1 to set RemoveBtRestriction to execute javascript ¬
" document.getElementsByClassName('text-entry')[1].value=" & quoted form of myCaseNote & ""
end tell
Result: missing value
Solution
set myCaseNote to "MULTIPLE\\nLINE\\nTEXT\\nHERE"
Splitting the string over several physical lines as you did causes a syntax error in the JavaScript. Use a newline character instead.
I see you really love sticking on those empty strings at the end of your concatenations. I now recognise this as your trademark.
I momentarily deleted this answer when it didn't work as expected. Then I realised the newline character \n
needs to be escaped twice, so it's written as \\n
.
It's working now.
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange