Verify Display of 'Continue as' Button in Mobile Web Browser Using Appium

Modified on Fri, 1 Mar at 7:10 PM

This custom action is a method written in Java for Appium automation testing. It is written to verify whether the "Continue as <username>" button is displayed on a mobile web page in the Chrome browser.


Custom Method

public boolean VerifyDisplayedContinueas() {
        boolean isVerified = false;
        WebBrowser.setCurrentBrowser(0);
        browser = WebBrowser.driver_mobile;
        int i = 0;
        while (i < 5) {
            try {
                browser.context("NATIVE_APP");
                WebElement continueButton = browser
                        .findElement(By.id("com.android.chrome:id/account_picker_continue_as_button"));
                if (continueButton.isDisplayed()) {
                    isVerified = true;
                }
                if (isVerified) {
                    browser.context("CHROMIUM");
                    break;
                }
                i++;
            } catch (Exception ex) {
                browser.context("CHROMIUM");
                isVerified = false;
                i++;
            }
        }
        return isVerified;
    }


Functionality Summary

The following table provides method's functionality breakdown:

Field Description
Setting Browser Context:
It sets the browser context to "NATIVE_APP" to interact with native elements of the mobile app and then switches back to "CHROMIUM" context to interact with the web elements.
Finding the Button
It attempts to find the "Continue as" button using its ID ("com.android.chrome:id/account_picker_continue_as_button").
Verifying Display
If the button is found and is displayed (such as, visible on the screen), the isVerified flag is set to true.
Breaking the Loop
If the button is found and verified, the loop is broken, and the method returns true
Exception Handling
If an exception occurs while finding or verifying the button, the method catches the exception, sets isVerified to false, and continues the loop.
Loop Limit
The loop runs a maximum of 5 times (i < 5) to retry finding and verifying the button.
Return Value
The method returns true if the "Continue as" button is found and displayed within the specified number of attempts; otherwise, it returns false.


This custom action is useful for scenarios where the presence of the "Continue as" button needs to be verified before proceeding with further actions in the test script.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article