Accept/Dismiss alert - Android on Windows

I am using Appium 1.3.1 in Android. My test script contains an alert that should be accepted in order to move on with the rest of the steps. Currently ChromeDriver has a bug and can’t accept/dismiss alert.

I can accept/dismiss the alert by switching to native context and using native buttons to accomplish that.

The only problem now is that when I switch back to the webview context, Chromedriver won’t be able to process any new commands as it still sees a displayed alert. The only possible workaround that I can think of, is to kill the Chrome driver session and clear all of its traces. A new session would be created whenever it’s required.

Does anyone know how can I terminate and clear the chromedriver session without affecting the current appium session?? I tried killing the chromedriver process from task manager, but Appium still sees an active chromedriver session and this causes the following commands to fail.

Any helping ideas???

I had to reset the whole Appium session and start a new session in order to overcome the ChromeDriver bug :frowning:… does anyone know any simpler/less time consuming solution??

@Hassan_Radi. Would you give details about resetting the appium session? I’m running into this same issue and need a work around even if it is time consuming. Must completely automate the process.

@pmneve
It was an old bug in the ChromeDriver that has been solved now. It should be working in the latest Appium version.

In case it didn’t work, you can always inject JavaScript to take care of this issue (simpler, less time consuming approach for handling alerts if the ChromeDriver bug ever happened again)

To accept alerts by default:

webDriver.executeScript(“window.confirm = function(){return true};”);

To dismiss alerts by default:

webDriver.executeScript(“window.confirm = function(){return false};”);

You need to inject the JavaScript before the Alert is displayed on the screen in order for it to work effectively. For example: if a button shows the alert window, you need to inject the JavaScript before you click on the button.

Thanks @Hassan! Am seeing problem in Android Emulator with chromedriver 2.9. May not be a chromedriver issue at all. Will put this js in my toolbox…

@Hassan, Finally able to send the correct arguments to chromedriver to get it to do what I need.
Thanks for your help!