【问题标题】:AppleScript set value to web form input field via JavaScriptAppleScript 通过 JavaScript 将值设置为 Web 表单输入字段
【发布时间】:2017-05-09 19:23:51
【问题描述】:

我正在尝试通过 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

【问题讨论】:

    标签: javascript forms safari applescript registration


    【解决方案1】:

    我找到了答案:

    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
    

    【讨论】:

      【解决方案2】:

      感谢您的发帖,尼克!

      我需要添加退货。下面的代码是针对已经打开到网页的选项卡,因此不需要设置 url。

      to inputByID(theId, theValue) -- creates the function
      
      tell application "Safari" -- tells AppleScript to use Safari
          
          do JavaScript "  document.getElementById('" & theId & "').Focus();" in document 1
          
          delay 1
          
          do JavaScript "  document.getElementById('" & theId & "').Select();" in document 1
          
          delay 1
          
          do JavaScript "  document.getElementById('" & theId & "').value ='" & theValue & "';" in document 1
          
          delay 1
          
          tell application "System Events"
              keystroke space
              keystroke return
          end tell
          
      end tell -- stops using safari
      

      end inputByID --标记函数的结束

      【讨论】:

        猜你喜欢
        • 2013-10-14
        • 2013-05-15
        • 2023-01-18
        • 1970-01-01
        • 2021-12-16
        • 2013-04-12
        • 2019-05-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多