how to handle alerts in android using appium

后端 未结 9 1895
野趣味
野趣味 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:39

    If the alert display on Ui , taking more time to display when we need to wait ..we can use fluent wait instead of this..

    0 讨论(0)
  • 2020-12-11 08:40

    Some alerts may be native Android's alerts, not generated by a browser. In this case the following code:

    Alert alert = driver.switchTo().alert(); alert.accept();

    may throw: WebDriverException: unknown error: unhandled inspector error: {"code":-32603,"message":"No JavaScript dialog to handle"}

    To handle such alert, just switch to the native application context, make required actions, and then switch back to the browser:

    AppiumDriver<WebElement> appiumDriver = (AppiumDriver<WebElement>) webDriver;
    String currentContext = appiumDriver.getContext();
    appiumDriver.context("NATIVE_APP");
    
    // actions within the alert
    appiumDriver.findElements(By.xpath(OK_BUTTON_LOCATOR)).click(); // put locator instead of OK_BUTTON_LOCATOR
    appiumDriver.context(currentContext);
    
    // continue working
    
    0 讨论(0)
  • 2020-12-11 08:40
    WebElement btn = driver.findElement(By.xpath("//android.widget.Button[@content-desc='OK']"));
    TouchAction act = new TouchAction(driver);
    act.tap(241,320).perform();
    

    (241,320) these are X & Y c ordinates of alert This work perfectly for me

    0 讨论(0)
提交回复
热议问题