[英]Applescript waiting for a page to load
在繼續執行applescript之前,我嘗試了各種解決方案來輪詢elementID。 我更喜歡投票而不是任意拖延。
set pageNotLoaded to true
set doForThisID to do JavaScript "document.getElementById(‘thisElementID‘);"
repeat while pageNotLoaded is true
try
if (doForThisID contains "thisElementID") then
set pageNotLoaded to false
end if
end try
end repeat
我嘗試了網絡上提供的各種解決方案,但都沒有成功。 任何人都可以提供任何建議以使此代碼正常工作嗎?
您的某些邏輯不正確,使事情變得混亂。 另外,最佳做法是讓JavaScript通過嵌套.contains傳遞布爾值。 這是一個使用三種方法測試頁面是否已加載的腳本:
一個javascript document.readyState
一個javascript document.contains
一個簡單的Safari調用,用於查找文檔文本以查找字符串。
您可以更改此腳本以僅使用其中之一。
property testingID : "login"
property testingString : "Username:"
set pageLoaded to false
tell application "Safari"
repeat while pageLoaded is false
set readyState to (do JavaScript "document.readyState" in document 1)
set foundID to (do JavaScript "document.contains(document.getElementById(" & quoted form of testingID & "))" in document 1)
set pageText to text of document 1
if (readyState is "complete") and (foundID is true) and (pageText contains testingString) then set pageLoaded to true
delay 0.2
end repeat
end tell
display dialog "Ready state of page: " & readyState & return & ¬
"ID is loaded: " & foundID & return & ¬
"Test string is loaded: " & testingString
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.