【问题标题】:Javascript within AppleScript 'cannot make script into type specifier' (for clicking button in Chrome)AppleScript 中的 Javascript '不能将脚本变成类型说明符'(用于单击 Chrome 中的按钮)
【发布时间】:2018-10-30 21:46:14
【问题描述】:

我正在尝试让苹果脚本点击单选按钮。我对此很陌生。我收到此错误:错误“Google Chrome 出现错误:无法将窗口 id 1.52181061E+9 的标签 ID 1.521810707E+9 的活动标签的脚本转换为类型说明符。”编号 -1700 从窗口 id 1.52181061E+9 的标签 id 1.521810707E+9 的活动标签的脚本到说明符

代码:

to clickID(theID)

tell application "Google Chrome"
    tell window 1 to tell (make new tab)
        set its URL to "https://www.colonialfirststate.com.au/FirstNet/FNA/Controls/AdviserHosting.aspx?Page=BusinessReporting"
        delay 5
        set theScript to "document.getElementById('" & theID & "')'.click();"
        execute javascript theScript in active tab
    end tell
end tell

结束点击ID clickID("optFormatCSV")

这是按钮的屏幕截图和检查元素的副本:

检查元素

请帮忙:(

【问题讨论】:

    标签: javascript applescript


    【解决方案1】:

    您的脚本有几个错误:

    tell application "Google Chrome"
        tell window 1 to tell (make new tab)
            set its URL to "https://www.colonialfirststate.com.au/FirstNet/FNA/Controls/AdviserHosting.aspx?Page=BusinessReporting"
            delay 5
            set theScript to "document.getElementById('" & theID & "')'.click();"
            execute javascript theScript in active tab
        end tell
    end tell
    

    ".click()" 之前有一个杂散引用,这使得 JavaScript 无效;并且您的目标是 active tab 块内的 tell (make new tab) 。是后者产生了您的错误:

    Can’t make theScript of active tab of tab id ... of window id ...

    没有像active tab 这样的对象属于window 1tab id ...(您刚刚创建的选项卡)。

    只需删除对active tab 的引用,您的代码就可以工作了。这是您更正后的处理程序的外观:

    tell application "Google Chrome"
        tell window 1 to tell (make new tab)
            set its URL to "https://www.colonialfirststate.com.au/FirstNet/FNA/Controls/AdviserHosting.aspx?Page=BusinessReporting"
            delay 5
            set theScript to "document.getElementById('" & theID & "').click();"
            execute javascript theScript
        end tell
    end tell
    

    系统信息: AppleScript 版本: 2.7 系统版本: 10.13.6 Chrome 版本: em> 69

    【讨论】:

    • 现在我得到了缺失值错误。从“事件”复制并粘贴:“告诉应用程序“Google Chrome”将窗口 ID 1.52181117E+9 的标签 ID 1.521811198E+9 的新标签集 URL 复制到窗口 ID 1.521811198E+9 的“colonialfirststate.com.au/FirstNet/FNA/Controls/…”执行标签 ID 1.521811198E+9 id 1.52181117E+9 javascript "document.getElementById('optFormatCSV').click();" end tell 结果:缺失值
    • 这本身不是错误,至少不是 AppleScript 错误。您的 AppleScript 代码已正确处理并运行。但是,missing value 表明您的 JavaScript 代码没有返回值,所以这有问题。仔细检查您的id 是否正确。首先尝试在 Web 检查器中运行 JavaScript 代码以确保其正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    相关资源
    最近更新 更多