how to handle alerts in android using appium

后端 未结 9 1896
野趣味
野趣味 2020-12-11 08:18

How do I handle alerts in an Android web application using Appium server (1.0.1) and the Android SDK?

The below code is not working on android:

drive         


        
9条回答
  •  [愿得一人]
    2020-12-11 08:19

    // first check alert is present or not

    public boolean isAlertPresent() {
        try {
            mobDriver.switchTo().alert();
            log.info("ALERT IS PRESENT !! ");
            return true;
        } catch (Exception e) {
            log.info("ALERT IS NOT PRESENT !! ");
            return false;
        }
    }
    
    public void mobileAlertHandle() {
        if (isAlertPresent()) {
            Alert alert = mobDriver.switchTo().alert();
            alert.accept();
       }
    }
    

    if this does not work then inspect your element and try with id or name

    ex: mobDriver.findElementById("android:id/button2").click()

提交回复
热议问题