Im trying to use the Dialog answer to enter value on a website using Applescript.
display dialog "Enter In-Shift" default answer ""
set x_answer to text returned of result
tell application "Safari"
set longerVariable to variable1 & " " & variable2
The second is that you’ll need to properly quote the
he replied 'nothing' to me
’he replied '\''nothing'\'' to me'
when it should be
’he replied \'nothing\' to me'
Whenever I run into this problem, I look for a built-in way to solve it, and it doesn’t exist; the problem is exacerbated by AppleScript’s inability to easily replace text within a string. What ends up being necessary is a custom handler for replacing text; the standard way of replacing text in AppleScript is by manipulating text item delimiters: changing the delimiter to the text to be replaced, breaking the string into its text items, changing the delimiter to the text to be replaced with, and putting the parts back together into a string.
It’s not pretty, but there it is.
I’ve changed your example to use the answer box on Stack Overflow (class: wmd-input) for easy testing.
Note that your code uses getElementsByClassName, but your title asks about getElementById. In general, it will be safer to use getElementById if it’s feasible, because there can be only one.