How to capture the Toast in Android with appium

2019-09-16 17:24发布

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.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-16 18:18

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!

查看更多
登录 后发表回答