如何使用 appium 在 Android 中捕获 Toast [英] 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 + "')]")));
但它在您知道 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");
感谢 xpath 语法!
这篇关于如何使用 appium 在 Android 中捕获 Toast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!