2015-10-07 66 views
0

我看過這三個職位:取消按鈕被竊聽時不採取任何措施

  1. Handling Alert with UIAutomation

  2. UIAutomation : Cancel button on Alert view is tapped without actually doing it

  3. UIATarget.onAlert = function onAlert(alert) Issue - Script doesn't seem to go into block correctly

,我知道這個問題可以修復。我試圖使用人們在帖子中提出的方法,但它並不適合我。我想再次問這裏...

所以我需要在警報窗口上輸入密碼。就像這樣:

target.frontMostApp().keyboard().typeString("1234");

我想知道我是否應該先寫onAlert功能,並把此行的代碼onAlert功能之後?或者先寫入onAlert函數,然後將這一行代碼放入onAlert函數中?

我試圖做這樣的事情:

UIATarget.onAlert = function onAlert(alert) 

{ 

    return true; 

    target.frontMostApp().keyboard().typeString("1234"); 

} 

但它不工作...按鈕仍然被點擊的取消...謝謝!

回答

1

我看到兩個問題。首先,typeString行永遠不會執行,因爲它在函數中的return行之後。

function myExampleFunc() { 
{ 
    doSomething(); // executes 
    return true; // exits from the function 
    doAnything(); // never executed. ever. 
} 

的第二件事情是,它看起來像你想抓住多數民衆贊成由您自己的應用程序生成警報:

target.frontMostApp().keyboard().typeString("1234"); 

不要使用onAlert捕獲這些; onAlert用於處理iOS警報,如權限彈出窗口。

相關問題