简体   繁体   English

无法在 Appium 自动化中找到 Android 应用程序的 Snackbar

[英]Not able to find Snackbar of Android app in Appium automation

I have a ToDo Android app which shows a Snackbar whenever a new ToDo is saved.我有一个 ToDo Android 应用程序,它会在保存新的 ToDo 时显示一个 Snackbar。 In my automation test I am not able to capture the Snackbar so I tried with following xpath driver.findElementByXPath("//*[@text='TO-DO saved']").isDisplayed() and also tried driver.findElementByAndroidUIAutomator("new UiSelector().text(\\"TO-DO saved\\")").isDisplayed() but didn't get success.在我的自动化测试中,我无法捕获 Snackbar,所以我尝试使用以下 xpath driver.findElementByXPath("//*[@text='TO-DO saved']").isDisplayed()并尝试了driver.findElementByAndroidUIAutomator("new UiSelector().text(\\"TO-DO saved\\")").isDisplayed()但没有成功。

Can anybody help me to get the Android Snackbar element in appium?有人可以帮我在 appium 中获取 Android Snackbar 元素吗?

I've noticed that it happens only when the Snackbar contains action button, when it doesn't, Appium finds it very fast.我注意到只有当 Snackbar 包含操作按钮时才会发生这种情况,当它没有时,Appium 发现它非常快。 I still didn't find any solution.我仍然没有找到任何解决方案。

Snackbar is element that appears only in certain condition and often for a short period of time. Snackbar 是仅在特定条件下出现且通常在短时间内出现的元素。

You can try catching it with FluentWait :您可以尝试使用FluentWait捕捉它:

FluentWait<WebDriver> wait = new WebDriverWait(driver, 10).ignoring(NoSuchElementException.class);
wait.until(visibilityOfElementLocated(By.xpath("//*[@text='TO-DO saved']")));

Default polling period is 500 milliseconds , should be enough in most cases.默认轮询周期为500 毫秒,在大多数情况下应该足够了。

Still think its better to replace xpath locator with id, probably you have to add resource-id for snackbar if its not in place.仍然认为用 id 替换 xpath locator 更好,如果它没有到位,可能你必须为小吃店添加resource-id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM