问题
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