driver.switchTo().alert().accept() is not working on Safari


I want to accept a pop-up dialogue which Safari on a real device shows when it opens a new tab.

  1. My test script is clicking on a link <a href=“xxx” tartget="_blank">.
  2. I have set “Block Pop-Ups” OFF in Settings app. I am looking at the Safari alert on real device, which says “This site is attempting to open a pop-up window”.
  3. Neither driver.switchTo().alert().accept() nor autoAcceptAlerts=True are working.
  4. Appium is calling AppiumDriver.getAlertText(). I guess this is as a result of calling driver.switchTo().alert().
  5. My script ends with “org.openqa.selenium.NoAlertPresentException: An attempt was made to operate on a modal dialog when one was not open. (WARNING: The server did not provide any stacktrace information)”

Mac 10.12.4
Xcode 8.3
Appium 1.6.3
iPhone 7 with iOS 10.2.1

My Script
//Clicking <a href=“xxx” target=’_top’>
WebElement link2 = driver.findElement(By.linkText(“Open in a new window”));;

//Safari says “This site is attempting to open a pop-up window” [Block | Allow]
try{Thread.sleep(10000); }catch(InterruptedException e){}

Appium Log

Any suggestions help. Thanks in advance.