0

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

  • As I have told you in one of your other questions, using ` & ""` at the end of a line of code does absolutely nothing whatsoever! In other words, you're concatenating literally nothing to the end of the line of code. JavaScript code in this use case typically ends with a semi-colon, so if anything you should concatenate ` & ";"` afterwards! – user3439894 May 12 '18 at 13:06
1
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.

  • Yes I keep getting the wrong snippet with the empty strings.... the answer work perfectly, I will found a script to automatically replace the line with \n thank you! – Kevin May 12 '18 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .