Search code examples
androidappiumtoast

How to capture the Toast in Android with appium


I used like this,but not found.

WebElement element = androidDriver.findElementByClassName(android.widget.Toast);

So I search in every major forum and portal,they solved it by blow:

WebDriverWait wait = new WebDriverWait(androidDriver, 3); WebElement toastView = wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath(".//*[contains(@text,'" + toast + "')]")));

But it works well in the condition of you has known the toast text.


Solution

  • Here is my finally solution:

    WebElement toastView = androidDriver.findElement(By.xpath("//android.widget.Toast[1]")); String text = toastView.getAttribute("name");

    Thanks for the xpath grammar!