如何使用Appium在Android中捕获Toast [英] How to capture the Toast in Android with appium

查看:483
本文介绍了如何使用Appium在Android中捕获Toast的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经这样使用,但是没有找到.

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 + "')]")));

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.

推荐答案

这是我的最终解决方案:

Here is my finally solution:

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

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

感谢xpath语法!

这篇关于如何使用Appium在Android中捕获Toast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆