javascript - 无法获得关于何时使用 applescript 调用 jquery 的正确时机
问题描述
我正在尝试使用 applescript 和 javascript (jquery) 的组合来模拟作为 microsoftoline.com 中的特定用户的登录。首先,我需要知道“以前登录到 MSFT 列表”中有多少用户。我尝试通过检查 MSFT 登录屏幕中列出的行数来做到这一点。一旦我有了“Numusers”,然后我在每一行中迭代 HTML 以单击感兴趣的用户 ID div。问题是,我似乎无法确定何时运行 jquery 以获得这么多用户的时间。我有所有其他部分工作,只是不是 jquery 部分。
到目前为止,这是我的代码:
tell application "Safari"
activate
make new document with properties {URL:"http://login.microsoftonline.com"}
delay 3
set NumUsers to do JavaScript "$('div.tile-container').length" in
current tab of first window
display dialog NumUsers
end tell
作为回应,我收到一条错误消息,指出“未定义变量 NumUsers”。
我已经尝试过很多事情,包括在调用 jquery 之前等待页面加载。但我似乎也无法让它工作。该特定的编码尝试如下所示:
tell application "Safari"
activate
if not (exists document 1) then reopen
tell current tab of window 1 to set URL to "http://login.microsoftonline.com"
set the_state to missing value
repeat until the_state is "complete"
set the_state to (do JavaScript "document.readyState" in document 1)
log "busy"
delay 0.2
end repeat
log "complete"
set NumUsers to do JavaScript "$('div.tile-container').length" in current tab of window 1
delay 2
display dialog NumUsers
end tell
我不喜欢使用 safari 作为源浏览器。
解决方案
毕竟不需要使用jquery。
这有效:
set NumUsers to do JavaScript "document.getElementsByClassName('tile-container').length" in current tab of window 1
推荐阅读
- ios - Xcode 10.1 - 模拟器崩溃尝试在横向 iPhone 8 Plus、iPhone XR 和 iPhone XS Max 中呈现 SKStoreProductViewController
- javascript - 当一个字符串以另一个字符串结尾时的字符串操作
- c - C中的空结构
- hadoop - 大数据堆栈不那么开放,导致安全需要 Ranger 和 Sentry
- r - 在R中将json转换为数据框
- google-play-services - RealTime Multiplayer:表示通过邀请启动
- python - 通过 python 库调用函数 AudioConfig.FromWavFileInput 时出现问题
- c++ - 带增强绑定的异步接受
- python - 动态编程 - 4 键键盘
- javascript - Chrome devtools 悬停窗口