2014-02-24 61 views
3

一個對話框,以這樣的方式來實現的應用程序:如何使用Appium通過硒查找警報對話框?

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Something"); 
builder.setTitle("Something"); 
dialog = builder.create(); 
dialog.show(); 

我怎麼能找到Appium測試腳本這個元素?

driver.switchTo().alert();拋出NotImplementError

driver.findElement(By.tagName("AlertDialog"))不工作

而且我發現這個問題Alert methods NYI Github上。有什麼解決方法嗎?順便說一下,我不打算在該對話框上點擊「確定」或「取消」,我即將等到該對話框自動消失。

在此先感謝。

回答

3

請使用下面的代碼爲你的需要:

等待警報出現:

wait.until(ExpectedConditions.alertIsPresent()); 

等待警報消失:

wait.until(!ExpectedConditions.alertIsPresent()); 
0

對於我來說,當我這樣做接受警報對話框時OK按鈕OK按鈕

driver.findElement(By.name("OK")).click() 

但完成點擊動作後,我的程序停止檢測元件

+0

他們並不想解除警報,他們需要等待,直到它自動解散。 – sheeptest

1

等待警報消失:

wait.until(ExpectedConditions.not(ExpectedConditions.alertIsPresent()));