javascript - AppleScript 通过 JavaScript 将值设置为 Web 表单输入字段

标签 javascript forms safari applescript registration

我正在尝试通过 Applescript 强制注册。有一个表单字段需要电子邮件。我已成功将电子邮件添加到表单字段,但它仍然未被识别为“值”。当我检查该元素时,该值未设置。但是,如果我单击表单字段并添加空格,则该值将被识别。我不知道如何解决这个问题。我尝试过使用 focus()、click()、多次击键,但无论我做什么,该值都不会使用 Applescript 设置。

set email to the text returned of (display dialog "Enter in Your Email to Validate Your Purchase:" default answer "")

tell application "Safari"
        make new document at end of documents
        set URL of document 1 to "https://myurl.com"
        tell application "System Events" 

            set theScript to "document.getElementById('email').value= '" & email & "';"

        end tell

        delay 3 

        do JavaScript theScript in document 1

end tell

最佳答案

我找到了答案:

tell application "Safari"
make new document at end of documents
set URL of document 1 to "https://www.myurl.com"

        delay 1
        do JavaScript "document.getElementById('email').focus();" in document 1
        delay 1
        do JavaScript "document.getElementById('email').select();" in document 1
        delay 1
        do JavaScript "document.getElementById('email').value = '" & email & "';" in document 1
        delay 1
        tell application "System Events"
            keystroke space
        end tell
end tell

关于javascript - AppleScript 通过 JavaScript 将值设置为 Web 表单输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43878280/

相关文章:

jQuery 在 FF 中有效,但在 Safari 中无效

html - Safari 渲染不同边框宽度错误

ios - 无法从表中打开 Safari

用于序列化表单并恢复/填充表单的 jQuery 插件?

c# - 如何使用数据注释属性类来使表单中的空字符串失效?

ruby-on-rails - 在 Ruby on Rails 中构建向导

javascript - 如何在 Javascript 中操作我的深层嵌套 json?

javascript - 如何在 focusout() 上提交 Ajax 表单

javascript - 使用 javascript 突出显示代码示例中的语法。

javascript - 部分字符串搜索 javascript 对象数组以查找针