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