Applescript 不会点击并且 returns 缺失值

Applescript won't click and returns missing value

我正在尝试创建一个脚本来点击我的 Safari,但它没有点击它。它只会 运行 很长时间然后结果将是:missing value。我不明白为什么它会有 missing value,但我只想点击一些东西。

my auto_login_driver()

on auto_login_driver()
    activate application "Safari"
    tell application "System Events"
        
        tell process "Safari"
            set xxx to first UI element
        end tell
        
        click at {1103, 261} -- used command shift 4 to capture the location
    end tell
end auto_login_driver

不行。因为网站的界面只响应真正的鼠标点击。要实际单击屏幕上的某个位置,您需要使用某种 鼠标工具(例如 MouseTools)。但还有另一种解决方案——使用 JavaScript。喜欢这里:

-- SCRIPT: automatically login me to my syte
-- written by user @Robert Kniazidis

-- EDIT here the URL
set loginurl to "https:" & "//kinozal-tv.appspot.com/login.php?"
set mylogin to "KniazidisR" -- EDIT here account NAME
set myPassword to "mySecretPassword" -- EDIT here the PASSWORD

tell application "Safari" to activate

tell application "Safari" to tell window 1 to tell tab 1
    open location loginurl
    my waitSafariWebPageLoading()
    -- EDIT here the ID of USERNAME html element (I have 'username')
    do JavaScript ("document.getElementById('username').value = '" & mylogin & "'")
    -- EDIT here the ID of PASSWORD html element (I have 'password')
    do JavaScript ("document.getElementById('password').value = '" & myPassword & "'")
    -- EDIT here the SUBMIT BOTTON's CLASS NAME (I have 'buttonS')
    do JavaScript ("document.getElementsByClassName('buttonS')[0].click();")
end tell

on waitSafariWebPageLoading()
    tell application "System Events" to tell application process "Safari"
        repeat until (UI element "Reload this page" of group 3 of toolbar 1 of window 1 exists) or (UI element "Reload this page" of group 2 of toolbar 1 of window 1 exists)
            delay 0.1
        end repeat
    end tell
end waitSafariWebPageLoading

备注:

  1. JavaScript 应允许在 Safari 中执行。
  2. 要查找用户名 HTML 元素的 ID、密码 HTML 元素的 ID 和提交按钮的 class 名称,单击它们并使用 Safari 的 Inspect Element 检查。