我正在尝试编写一个applescript,它在浏览器中打开一个html页面,等待它加载,然后运行window.find来检查特定的关键字。 非常重要的是,.find 可以在页面加载后立即运行,但之前不会尝试。 如果存在关键字,脚本将单击“下一步”按钮。 这是我尝试制作的一个循环,用于检查 html 是否已加载
to checkInteractive()
repeat 60 times
try
tell application "Safari"
set a to do JavaScript
"document.readyState" in document 1
end tell
end try
if a = "interactive" then
exit repeat
end if
delay 0.01
end repeat
end checkInteractive
但我收到此错误:
语法错误无法在文档 1 中获取“document.readyState”。不允许访问。
有谁知道我应该做些什么不同的事情? 或者是否有另一种方法来检查html是否已加载?
最佳答案
将语句放在一行中
tell application "Safari"
set a to do JavaScript "document.readyState" in document 1
end tell
或使用 AppleScript 行分隔符
tell application "Safari"
set a to do JavaScript ¬
"document.readyState" in document 1
end tell
关于javascript - document.readyState "Access not allowed"与 Applescript +Javascript 等待页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36768305/