AppleScript - 如何 select 弹出按钮中没有标题的菜单项?

AppleScript - how do I select a menu item in a pop up button that has no title?

AppleScript 相对较新...

我正在尝试创建一个 AppleScript 来在 Firefox 中自动执行 File/Save Page As... 操作。具体来说,我需要从“另存为...”对话框中 select "Web Page, complete" 而不是对话框底部弹出按钮中的默认 "All Files" selection . (我正在使用 Firefox 和这个选项,因为我想在某些 JavaScript 代码具有 运行 之后保存当前的 html 内容 - 以解析出后续处理的值)。

我已经能够通过 select 使用弹出菜单(没有标题)解决这个问题:

((pop up buttons of window "Save As") whose description is "All Files")

并通过将击键 "w" 发送到 pop-up 菜单中的 select "Web Page, complete"。

我正在尝试找到一种更可靠的方法来执行此操作,而不是依赖于 "w" select 是我想要的菜单项这一事实。我试过了:

click menu item "Web Page, complete" of 
    ((pop up buttons of window "Save As") whose description is "All Files")

但这没有用。在查看辅助功能检查器时,弹出按钮(下拉列表)和菜单项之间似乎有一个菜单,但我不知道如何引用它。

如有任何帮助,我们将不胜感激。这是完整的脚本:

tell application "Firefox" to activate
delay 0.25

    tell application "System Events"

        tell process "Firefox"
            set frontmost to true

            click menu item "Save Page As…" of menu "File" of menu bar 1
            delay 0.25

            repeat until window "Save As" exists
                delay 0.5
            end repeat

            click ((pop up buttons of window "Save As") whose description is "All Files")
            delay 0.5

            -- This didn't work:
            click menu item "Web Page, complete" of ((pop up buttons of window "Save As") whose description is "All Files")

            -- This works but only because the first entry is "Web Page, complete"
            keystroke "w"
            keystroke return
            delay 0.5

            set outputfilename to "foo3.html" as text

            keystroke outputfilename
            keystroke return

            delay 0.5
      end tell
end tell

试试这个

activate application "Firefox"

tell application "System Events"

    tell process "Firefox"
        set frontmost to true
        click menu item "Save Page As…" of menu "File" of menu bar 1
        repeat until window "Save As" exists
            delay 0.2
        end repeat

        tell window "Save As"
            tell pop up button 1 of group 1
                if value is not "Web Page, complete" then
                    click
                    delay 0.5
                    pick menu item "Web Page, complete" of menu 1
                end if
            end tell

            set outputfilename to "foo3.html"
            keystroke outputfilename
            click button "Save"
        end tell
    end tell
end tell