おい。
実際、Apple からのドキュメント ( thisおよびthis ) は、私が見つけた唯一のものです。
あなたの質問については試してみてください
if(UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].name() === "beep sound")) {
UIALogger.logPass("Buton Present");
} else {
UIALogger.logFail("Buton Not Present");
};
もちろん、これは ( elements()[0] ) ボタンがメイン ウィンドウの下のオブジェクト ツリーの最初にあることを前提としています。そうでない場合は、他の要素 (( elements() 3 ) を呼び出す必要があるか、より深い階層 ( elements()[0].elements() 3 )を呼び出す必要がある場合があり
ます)。チェーン内のオブジェクトの 1 つが存在しない場合は失敗します. チェーン内のすべてのオブジェクトをチェックする必要があるかもしれません. さらに, 特定のボタンが存在するかどうかだけでなく, 画面に表示されているかどうかもチェックする必要があるかもしれません. この場合, 上記のコード次のようにする必要があるかもしれません:
if(UAITarget.localTarget().frontMostApplication().mainWindow() && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0] && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate("name matches 'beep sound'")) {
if(UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].isVisible()) {
UIALogger.logPass("Buton Present");
} else {
UIALogger.logFail("Buton Present, but Not Visible");
}
} else {
UIALogger.logFail("Buton Not Present");
};
しかし今では、コードの可読性、保守性、過度の属性が犠牲になっています。したがって、次のようにリファクタリングします。
function isButtonWithPredicate (predicate) {
if(UAITarget.localTarget().frontMostApplication().mainWindow() && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0] && UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate(predicate)) {
return true;
} else {
throw new Error("button not found, predicate: " + predicate);
}
function getButtonWithPredicate (predicate) {
try {
if(isButtonWithPredicate(predicate)) {
return UAITarget.localTarget().frontMostApplication().mainWindow().elements()[0].withPredicate(predicate);
}
} catch (error) {
throw new Error("getButtonWithPredicateError: " + error.message);
};
}
var strpredicate = "name matches 'beep sound'";
var objButton = null;
try{
objButton = getButtonWithPredicate(strPredicate);
if(objButton.isVisible) {
UIALogger.logPass("Buton Present");
};
} catch(error) {
UIALogger.logFail(error.message);
}
もちろん、それを改善することはできます...しかし、アイデアを得る必要があります。
ところで、述語へのアップルガイド
PS コードはメモ帳で書かれており、チェックされていないため、解析エラーが含まれている可能性があります。