如何在Appium中忽略Raaga应用的选择账户弹窗?
Hey there! I’ve run into exactly this kind of system-style account picker popup (just like Google Play’s) when automating apps before, so let’s walk through the most reliable ways to skip or ignore it in Appium.
Method 1: Leverage Appium’s Built-in Popup Handling Capabilities
For Android, you can configure your desired capabilities to auto-handle common system popups. These settings tell Appium to dismiss or accept non-critical alerts without manual intervention:
Python Example
desired_caps = { "platformName": "Android", "deviceName": "your_device", "appPackage": "com.raaga.android", "appActivity": "com.raaga.android.SplashActivity", "autoGrantPermissions": True, "ignoreUnimportantViews": True, "autoAcceptAlerts": True, # Targets system-level alerts like account pickers "disableWindowAnimation": True # Reduces flakiness when popups load }
Java Example
DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Android"); caps.setCapability("deviceName", "your_device"); caps.setCapability("appPackage", "com.raaga.android"); caps.setCapability("appActivity", "com.raaga.android.SplashActivity"); caps.setCapability("autoGrantPermissions", true); caps.setCapability("ignoreUnimportantViews", true); caps.setCapability("autoAcceptAlerts", true); caps.setCapability("disableWindowAnimation", true);
Method 2: Manually Locate and Dismiss the Popup
If the built-in settings don’t catch the popup, use Appium Inspector to identify the "Skip" or "Later" button (or any bypass option) and interact with it directly. This gives you precise control over the popup:
Python Example
from appium.webdriver.common.appiumby import AppiumBy from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException try: # Wait up to 10 seconds for the popup to appear skip_button = WebDriverWait(driver, 10).until( EC.presence_of_element_located((AppiumBy.ID, "com.raaga.android:id/btn_skip")) ) if skip_button.is_displayed(): skip_button.click() except TimeoutException: # Popup didn't load, proceed with your test pass
Java Example
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; import io.appium.java_client.AppiumBy; import org.openqa.selenium.TimeoutException; try { WebDriverWait wait = new WebDriverWait(driver, 10); MobileElement skipButton = wait.until( ExpectedConditions.presenceOfElementLocated(AppiumBy.id("com.raaga.android:id/btn_skip")) ); if (skipButton.isDisplayed()) { skipButton.click(); } } catch (TimeoutException e) { // No popup detected, continue test execution }
Pro tip: If it’s a system-level account picker (not part of Raaga’s UI), target elements using Android’s system package like com.google.android.gms instead.
Method 3: Launch the App Directly to the Main Activity
The account popup often only appears on the splash screen. Bypass it entirely by launching the app’s main home activity directly:
- First, find the main activity using ADB:
adb shell dumpsys window | grep mCurrentFocus
- Look for a line like
mCurrentFocus=Window{... u0 com.raaga.android/com.raaga.android.ui.home.HomeActivity}— the part after the slash is your target activity. - Update your desired capabilities to use this activity:
desired_caps["appActivity"] = "com.raaga.android.ui.home.HomeActivity"
Method 4: Use No Reset to Retain Session State
If you only need to dismiss the popup once, enable the noReset capability. This keeps the app’s state between test runs, so after you dismiss the popup once, subsequent launches won’t show it:
desired_caps["noReset"] = True
Note: This isn’t ideal for fresh test environments, but it’s a quick fix for recurring test runs.
I’d recommend starting with Method 1 or 3 since they’re the most maintainable. If those don’t work, Method 2 gives you full control over the popup. Let me know if you need help identifying specific elements!
内容的提问来源于stack exchange,提问作者Love

