Can't tap on OK button in alert dialog on real device

  • running on real device Galaxy Nexus 4.3
  • appium version 1.3.7
  • Mac OS 10.10.3
  • java client version 2.2.0
  • selenium 2.45

Hello, I’d like to find way how to simply tap on the OK button.
I am using
driver.findElementById(“android:id/button1”).click();
where ‘android:id/button1’ is resource-id.

Seems as this command is not executed at all and no click is performed.

Thanks !

Hi,
Have you ever tried with switchToAlert…
Alert alert = driver.switchTo().alert();
alert.accept(); (or) driver.findElementById(“android:id/button1”).click();

Please have a try…
Regards,
Bhaskar.

Hi,

I am also facing same issue. I get the same ‘Not yet implemented’ issue. Any solution?

It’s an android element, it’s visible in the inspector as well as android uiautomatorviewer

Method that works for me in C#. Hope this helps.

        public void ClickPopupButton(string buttonText)
    {
        //wait up to 5 seconds for the alert to appear
        for (var i = 0; i < 5; i++)
        {
            if (this.IsAlertPresent())
            {
                IList<IWebElement> buttonCells = driver.FindElement(eAlertButtonCollection).FindElements(By.ClassName("android.widget.Button"));
                foreach (IWebElement cell in buttonCells)
                {
                    if (cell.Text.Contains(buttonText, StringComparison.InvariantCultureIgnoreCase))
                    {
                        cell.Click();
                        break;
                    }
                }

                break;
            }
        }
1 Like

Any Solution for JAVA please.

I too face the same issue here.

I even tried with baskar solution:
Alert alert = driver.switchTo().alert();
alert.accept(); (or) driver.findElementById(“android:id/button1”).click();

This dint work for me.

Hi,

Try to put some wait before clicking on OK button and if it is having text attribute as ‘OK’, then have a try with
driver.findElement(By.name(“OK”)).click();

Regards,
Bhaskar.

1 Like

Yeah, when automating the simulator or real device doesn’t perform fast operations as like real device app. So putting wait and driver.findelement(By.xpath(“xapath address”).click(); will work. In my experience sometime Byname doesn’t work and sometime ByXpath so we should try to use whatever is possible.

Try this

driver.findElement(By.name(“OK”)).click();

Use the below code, This will help.

synchronized (driver)
{
driver.wait(2000);
}
driver.context(Constants.NATIVE_APP);

driver.findElementByXPath("//android.widget.Button[@resource-id=‘android:id/button1’]").click();