How to handle Alert box / Pop up using JAVA for Android?

Hi,
I have the same issue about not being able to select alerts on different Android fragments. Can you please specify a method other than below?

  1. driver.switchTo().alert();
  2. driver.elementByXPath
  3. driver.elementById

I tried all of these options and still did not get a result in the following structure:

<android.widget.FrameLayout>
<android.widget.LinearLayout>
	<android.widget.FrameLayout resource-id="android:id/content">
		<android.widget.LinearLayout>
			<android.widget.ImageView resource-id="xx/iv_custom_alert_icon">
			<android.widget.TextView resource-id="xx/tv_custom_alert_title">
			<android.widget.TextView resource-id="xx/tv_custom_alert_subtitle">
		<android.widget.LinearLayout>
			<android.widget.TextView resource-id="xx/v_custom_alert_positive"> 

alternative suggestions would be appreciated, thanks.

If this helps anyone, below locator strategy, worked for me:

By loc_acceptAlert = ByAndroidUIAutomator.AndroidUIAutomator("new UiSelector().text(\"YES\")");

By loc_dismissAlert = ByAndroidUIAutomator.AndroidUIAutomator("new UiSelector().text(\"NO\")");

1 Like