How to locate/Access snackbar elements? I am not able to find locators for snackbar

混江龙づ霸主 提交于 2020-06-01 05:33:10

问题


Android Automation using Appium: I am trying to verify/validate the snackbar. but Appium Inspector is not identifying the locators for snackbar. please help me how to validate the snackbar content.


回答1:


The easiest way to handle it is to check the source code of your Android application. Assuming you have a text view and button in Snackbar, you should be able to find smth like this:

<view
    class="android.support.design.internal.SnackbarContentLayout"
    >

    <TextView
        android:id="@+id/snackbar_text"/>

    <Button
        android:id="@+id/snackbar_action"
        android:visibility="gone"/>
</view>

If id is not in place, I suggest to add them by yourself. Now you should be able to spot your snack bar, get the text or click the button:

FluentWait<WebDriver> wait = new WebDriverWait(driver, 10, 100).ignoring(NoSuchElementException.class);
wait.until(visibilityOfElementLocated(By.id("snackbar_text")));



回答2:


For Android-: Never use Appium inspector for inspecting Snackbar messages.

Even I faced this issue earlier then I used UIAutomatorViewer and I found both text and id for Snackbar messages.

**

for e.g-:

resource id-:"vn.com.nitinsurange.mobile.uat:id/snackbar_text" text-: "Account number must be between 5 and 20 digits. (2142)"

**

    @iOSXCUITFindBy(xpath ="//*[@value='Username']")
@AndroidFindBy(id = "vn.com.nitinsurange.mobile.uat:id/snackbar_text")
private MobileElement invalidpassword;

Hope it will useful for all.



来源:https://stackoverflow.com/questions/53910811/how-to-locate-access-snackbar-elements-i-am-not-able-to-find-locators-for-snack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!