我正在使用 Instruments 创建一个 iOS UI 自动化 javascript,以自动为我的 iOS 应用程序截取屏幕截图。我用来自动截图的工具是 Snapshot .
我在我的应用程序的一部分中使用了 webview,我想在继续执行脚本的其余部分之前截取完全渲染的 webview 的屏幕截图。 所以目前我的脚本如下所示:
var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].links()[0].tap();
// take screen shot here
target.frontMostApp().navigationBar().leftButton().tap();
但是当它拍摄屏幕截图时, WebView 尚未完全渲染,因此它会拍摄一个空屏幕并返回主屏幕。 有没有办法等到 WebView 完全加载,然后拍摄屏幕截图并继续脚本的其余部分?
最佳答案
Illuminator 框架(完全公开,我编写的)在其 Extensions.js 中提供了一个名为 waitForChildExistence()
的函数。这允许您连续评估对元素的引用,直到它实际出现。
您可以执行以下操作来等待最多 10 秒以加载 Web View :
var webView = target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0];
webView.tap();
webView.waitForChildExistence(10, true, "a specific link in the web view", function(wb) {
// the argument wb will contain the reference to our var webView
return wb.links()["the link you are waiting for"];
});
// take screen shot here
target.frontMostApp().navigationBar().leftButton().tap();
关于javascript - iOS UI 自动化等待 Web View 准备好并渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28489380/