我想使用AppleScript通過Safari自動登錄網頁。使用AppleScript自動點擊對話框按鈕
當我打開一個URL並給出用戶名和密碼時,如果它是第一次還沒有保存密碼,它會顯示消息:「你想保存這個密碼嗎?」。
我想使用AppleScript來選擇「不是現在」。我怎樣才能做到這一點?
這裏是我當前的代碼:
tell application "Safari"
open location "http://www.amazon.com"
activate
end tell
if page_loaded(60) then
say "Page Loaded"
tell application "Safari"
set loginURL to do JavaScript "document.getElementById('nav-your-account').getAttribute('href')" in document 1
open location loginURL
end tell
else
say "Page Failed to load or Safari didn't open"
end if
if page_loaded(60) then
say "Page Loaded"
tell application "Safari"
do JavaScript "document.getElementById('ap_email').value = 'mritjp'; document.getElementById('ap_password').value = 'mritjp'; document.forms['signIn'].submit();" in document 1
---HOW TO CONTROL TO CHOOSE "Not Now" in message "Would you like to save this password?" of safari
activate
delay 2
end tell
else
say "Page Failed to load or Safari didn't open"
end if
on page_loaded(timeout_value) -- in seconds
delay 1
repeat with i from 1 to timeout_value
tell application "Safari"
if name of current tab of window 1 is not "Loading" then exit repeat
end tell
delay 1
end repeat
if i is timeout_value then return false
tell application "Safari"
repeat until (do JavaScript "document.readyState" in document 1) is "complete"
delay 0.5
end repeat
end tell
return true
end page_loaded
Fixed by comment of Lauri Ranta:
如果輔助設備的控制已經從系統首選項啓用後,您可以使用系統事件:
on enabledGUIScripting()
do shell script "sudo touch /private/var/db/.AccessibilityAPIEnabled" password "1" with administrator privileges
end enabledGUIScripting()
Then:
tell application "System Events" to tell process "Safari"
click button 3 of sheet 1 of window 1
end tell
如果勞裏·蘭塔的回答是解決你的問題,請點擊綠色的對勾答案旁邊接受。 –