[英]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.