Native iOS alert not closing on dismiss button click

Hello,

I have the following problem. In a iOS application at some point a popup appears after pressing some button.
The popup has only one button, an OK button. It’s a simple popup with title / content and one button, the OK button, which dismisses the popup if clicked.
I get the button element using the find by name strategy: driver.find_element(:name, "OK").
Once the element is found I retain it in a local variable and call the click method on that element so, the final code looks like this:
button_ok = driver.find_element(:name. "OK") button_ok.click
Nothing happens. In the Appium log console, I can see when the search element request is sent, and also when it is clicked.

info: → POST /wd/hub/session/f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5/element {“using”:“name”,“value”:“OK”}
info: [debug] Waiting up to 30000ms for condition
info: [debug] Pushing command to appium work queue: “au.getElementByName(‘OK’)”
info: [debug] Sending command to instruments: au.getElementByName(‘OK’)

info: [debug] [INST] 2016-01-26 19:23:13 +0000 Debug: Got new command 29 from instruments: au.getElementByName(‘OK’)

info: [debug] [INST] 2016-01-26 19:23:13 +0000 Debug: evaluating au.getElementByName(‘OK’)
info: [debug] [INST] 2016-01-26 19:23:21 +0000 Debug: evaluation finished

info: [debug] [INST] 2016-01-26 19:23:21 +0000 Debug: Lookup returned [object UIACollectionCell] with the name “OK” (id: 11).
info: [debug] [INST] 2016-01-26 19:23:21 +0000 Debug: responding with:
info: [debug] [INST] 2016-01-26 19:23:21 +0000 Debug: Running system command #30: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“ELEMENT”:“11”}}…

info: [debug] Socket data received (39 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:0,“value”:{“ELEMENT”:“11”}}
info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“11”},“sessionId”:“f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5”}
info: ← POST /wd/hub/session/f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5/element 200 8822.971 ms - 88 {“status”:0,“value”:{“ELEMENT”:“11”},“sessionId”:“f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5”}
info: → POST /wd/hub/session/f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5/element/11/click {}
info: [debug] Pushing command to appium work queue: “au.tapById(‘11’)”
info: [debug] Sending command to instruments: au.tapById(‘11’)

info: [debug] [INST] 2016-01-26 19:23:22 +0000 Debug: Got new command 30 from instruments: au.tapById(‘11’)

info: [debug] [INST] 2016-01-26 19:23:22 +0000 Debug: evaluating au.tapById(‘11’)
info: [debug] [INST] 2016-01-26 19:23:22 +0000 Debug: UIACollectionCell.tap()

info: [debug] [INST] 2016-01-26 19:23:24 +0000 Debug: evaluation finished

info: [debug] [INST] 2016-01-26 19:23:24 +0000 Debug: responding with:
info: [debug] [INST] 2016-01-26 19:23:24 +0000 Debug: Running system command #31: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:“”}…
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:0,“value”:“”}
info: [debug] Responding to client with success: {“status”:0,“value”:“”,“sessionId”:“f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5”}
info: ← POST /wd/hub/session/f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5/element/11/click 200 3216.305 ms - 74 {“status”:0,“value”:“”,“sessionId”:“f634ad9f-beaa-4a90-9b54-9da5fb9d0aa5”}

I also tried with xpath search strategy, the same result, the button is not clicked and the popup is not dismissed. The weird part is, that if I try this code in the arc console, it works.
I also tried with the alert_accept method suggested here (https://github.com/appium/ruby_lib/blob/master/docs/docs.md) and nothing, same result.
Another try was with this code: driver.switch_to.alert.accept and again, works on arc console but not in my test.
I also tried clicking on the coordinates of the OK button by using the location with the code from below, but still no luck.
button_ok = driver.find_element(:name. "OK") coordinates = button_ok.location driver.execute_script 'mobile: tap', :x => coordinates.x + 15, :y => coordinates.y + 15

The code is written in ruby and the application runs on iOS simulator (iOS 8.4).
Appium version: 1.4.13 (Draco), ruby version: 2.1.5, gem appium_lib version: 8.0.1, selenium-webdriver version: 2.49.0, OS: mac os el capitan.
Any suggestions would be appreciated very much.
Thank you.

Shouldn’t the parameters be separated by a comma (“,”)? As in:

button_ok = driver.find_element(:name, "OK")

I would think it was a typo but you put it that way twice in your description of the problem. Maybe it’s still a typo.

One other thing that bothers me about your description. You are finding an element with the name of, “OK”. It’s supposed to be a button on a dialog box, but the element you are finding is:

So the question is do you have an element in your app of type UIACollectionCell that is also named, “OK”, and that clicking that does so does something like select that cell, instead of clicking the button? How about if you tried something like this:

buttons = driver.tags('UIAButton')
buttons.each do |button|
  if button.name == "OK"
    button.click
  end
end

See if that kind of thing works better for you.