Hey Guys.
I am trying to simulate a mouse click on a button called “Working Time” on a web page. I wrote the following applescript, but it is not working properly. I am getting the following error.
Syntax Error
Expected end of line, etc. but found identifier.
Any ideas what is wrong? Is it my applescript or the javascript itself that is the problem?
tell application "Safari"
activate
do JavaScript "this.Response.Redirect("WebForm1.aspx?__EVENTTARGE T=Working Time")"
end tell
StefanK
February 4, 2009, 8:04pm
#2
Hi,
double quotes in literal strings must be escaped with a backslash
tell application "Safari"
activate
do JavaScript "this.Response.Redirect(\"WebForm1.aspx?__EVENTTARGE T=Working Time\")"
end tell
Thanks Stefan.
I have re-written this with a different approach with the same issue. I just don’t know where the backslashes should go.
tell application "safari"
activate
do JavaScript "var clickNode = document.getElementsById(thisNode);
clickNode.onclick("return me.h_e(event,window,this,'Link','LINKCLICK',{'event':'event','ControlId':'aaabGFON.AreaGroupViewStatic.Area2Link'},'',true);" href="javascript:void(0);" onkeydown="return me.h_m(event,window,'sapUrMapi_Link_activate(\'aaabGFON.AreaGroupViewStatic.Area2Link\',SSR.event)');");"
end tell
StefanK
February 4, 2009, 8:47pm
#4
every double quote within the literal string must be escaped as "
Got it. I have a new error now with the following:
tell application "Safari"
activate
do JavaScript "var clickNode = document.getElementsById(thisNode);
clickNode.onclick(\"return me.h_e(event,window,this,'Link','LINKCLICK',{'event':'event','ControlId':'aaabGFON.AreaGroupViewStatic.Area2Link'},'',true);\" href=\"javascript:void(0);\" onkeydown=\"return me.h_m(event,window,'sapUrMapi_Link_activate(\'aaabGFON.AreaGroupViewStatic.Area2Link\',SSR.event)');\");"
end tell
I seem to be getting the same problem with the single quotations in the java script. Does this have to be done with them as well?
StefanK
February 4, 2009, 8:55pm
#6
No, only the double quotes, but if there are backslashes in the text, you have also to escape the backslashes \