Javascript alert in real iOS device not working

Do anyone have solution how to handle javascript alert in real iOS device using Appium, the code i have below working fine in Android real device but same doesn’t work in iOS device. I have Web App (Browser base application) to automate. Any help will be appreciated as i am stuck in my project. Please guys share the idea if you have any solution for this.

	WebDriverWait wait = new WebDriverWait(driver,20 );
	wait.until(ExpectedConditions.alertIsPresent());
	Alert alert = driver.switchTo().alert();
    alert.accept();

Below is the Appium log while running script in real iOS device

info: [debug] [REMOTE] Executing ‘click’ atom in default context
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Remote debugger data sent [{“method”:“Runtime.evaluate”,“params”:{“objectGroup”:“console”,“includeCommandLineAPI”:true,“doNotPauseOnExceptionsAndMuteConsole”:true,“expression”:"(function(){return function(){function h(a){return…]
Debugger web socket received data : {“result”:{“result”:{“type”:“string”,“value”:"{“status”:0,“value”:null}"},“wasThrown”:false},“id”:34}
info: [debug] Responding to client with success: {“status”:0,“value”:null,“sessionId”:“24fbd20f-d04d-403b-bc6d-4774220bac7f”}
info: <-- POST /wd/hub/session/24fbd20f-d04d-403b-bc6d-4774220bac7f/element/5009/click 200 238.776 ms - 76 {“status”:0,“value”:null,“sessionId”:“24fbd20f-d04d-403b-bc6d-4774220bac7f”}
info: --> GET /wd/hub/session/24fbd20f-d04d-403b-bc6d-4774220bac7f/alert_text {}
info: [debug] Pushing command to appium work queue: “au.getAlertText()”
info: [debug] Sending command to instruments: au.getAlertText()
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Debug: Got new command 3 from instruments: au.getAlertText()
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Debug: evaluating au.getAlertText()
info: [debug] Socket data received (97 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:27,“value”:“An attempt was made to operate on a modal dialog when one was not open.”}
info: [debug] Responding to client with error: {“status”:27,“value”:{“message”:“An attempt was made to operate on a modal dialog when one was not open.”,“origValue”:“An attempt was made to operate on a modal dialog when one was not open.”},“sessionId”:“24fbd20f-d04d-403b-bc6d-4774220bac7f”}
info: <-- GET /wd/hub/session/24fbd20f-d04d-403b-bc6d-4774220bac7f/alert_text 500 994.757 ms - 244
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Error: VerboseError: An attempt was made to operate on a modal dialog when one was not open.
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Error: Error during eval: getAlertText@file:///usr/local/lib/node_modules/appium/0C0FF151-BC02-4E95-9860-DE51725DB02F/bootstrap-d9db640ed3c1df08.js:939:43
eval code
eval@[native code]
startProcessing@file:///usr/local/lib/node_modules/appium/0C0FF151-BC02-4E95-9860-DE51725DB02F/bootstrap-d9db640ed3c1df08.js:2685:30
bootstrap@file:///usr/local/lib/node_modules/appium/0C0FF151-BC02-4E95-9860-DE51725DB02F/bootstrap-d9db640ed3c1df08.js:2753:31
global code@file:///usr/local/lib/node_modules/appium/0C0FF151-BC02-4E95-9860-DE51725DB02F/bootstrap-d9db640ed3c1df08.js:2762:10
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Debug: responding with:
info: [debug] [INST] 2015-02-13 19:58:38 +0000 Debug: Running system command #4: /usr/local/Cellar/node/0.10.35/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:27,“value”:“An attempt was made to operate on a modal dialog when one was not open.”}…
info: --> GET /wd/hub/session/24fbd20f-d04d-403b-bc6d-4774220bac7f/alert_text {}
info: [debug] Pushing command to appium work queue: “au.getAlertText()”
info: [debug] Sending command to instruments: au.getAlertText()
ushofml916k:~ vsandes$ info: [debug] Didn’t get a new command in 60 secs, shutting down…
info: Shutting down appium session
info: [debug] Stopping ios
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Sending sigterm to instruments
info: [debug] [INST] 2015-02-13 19:59:36 +0000 Stopped: Script was stopped by the user
info: [debug] [INST] Instruments Trace Complete (Duration : 85.733749s; Output : /tmp/appium-instruments/instrumentscli0.trace)
info: [debug] [INSTSERVER] Instruments exited with code 0
info: [debug] Cleaning up after instruments exit
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killall iOS Simulator
info: [debug] Killing any other simulator daemons
info: [debug] [REMOTE] Disconnecting from remote debugger
info: [debug] On a real device; cannot clean device state
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in

1 Like

doesn’t work for me in my hybrid ios app have logged it several places.

@vinit @hardik_d I have used this in my code (hybrid ios) works for me. ensure you do have the alert\error message up before switching to alert. my code is in python.

  211 @then(u'Error Message is shown')
  212  def step_impl(context):
  213  	context.app.wd.implicitly_wait(60)
  214  	context.app.wd.switch_to_alert()
  215   context.app.wd.find_element_by_name("OK").click()

hey MS, yeah i think it is either waits work better now or ios9 fixed something in webview but now i am on my merry way with accessing those pop ups in webview and it works. Occasionally i do add sleeps in the mix. earlier i had to switch to native view to access them.