![](/img/trans.png)
[英]Photoshop Applescript calling JavaScript causing error “Expected end of line, etc. but found identifier”
[英]Expected end of line error on applescript trying to fill a webform
我试图提出一个我可以运行的Apple脚本,以便填写每天执行的某些Web表单(JIRA票证表单)。
我创建了这个JS脚本,当我在Chrome的控制台上运行该脚本时,该脚本可以正常工作:
document.getElementById('summary').value="Inserted text"
因此,现在我创建了自己的applescript,以便能够在外部执行它,但是我始终会收到“语法错误。期望行尾等,但发现未知标记” 。
这是代码:
tell application "Google Chrome"
execute javascript document.getElementById('summary').value="Inserted text" in document 1
end tell
我知道告诉应用程序有效,但是我不明白如何解决语法错误并使applescript有效
in document 1
语法适用于Safari。
使用Google Chrome浏览器时,您应该转到目标window
的active tab
,例如:
tell application "Google Chrome"
tell active tab of window 1
execute javascript "document.getElementById('summary').value = 'Inserted text';"
end tell
end tell
或将窗口号替换为其name
。
使用最新版本的Sierra对我有效
tell application "Google Chrome"
execute front window's active tab javascript "document.getElementById('summary').value = 'Inserted text';"
end tell
或 -仅压缩为一行代码
tell application "Google Chrome" to execute front window's active tab javascript "document.getElementById('summary').value = 'Inserted text';"
我选择此代码的原因是由于以下示例。
在Google Chrome浏览器中,我从一个窗口开始,然后从一个带有4个标签的窗口开始。 接下来,将这些选项卡拆分为4个单独的窗口。 之后,我选择了右下角的窗口,使其成为“活动窗口”。 认为右下角的窗口现在处于活动状态,将成为“第1窗口”……我错了(根据以下脚本的结果)
如果我在“ window 1”中运行脚本,它将在浏览器的左上方窗口中运行,当我只有一个带有一个选项卡的窗口时,它就是窗口1。 它保留了其初始值。 问题是不是我要在其上运行脚本的窗口
因此,显然窗口1不一定是前窗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.