Selenium C# How to handle Alert "Open Pick an app"?


I am trying to get the Alert’s Text using Selenium C# for Chrome

enter image description here

But this alert seems different from a normal JavaScript Alert, using the code below returns an error exception:

string text = driver.SwitchTo().Alert().Text;

OpenQA.Selenium.NoAlertPresentException: no such alert

Is this considered as an alert? Is there a way to handle it?


The dialog you’re seeing is shown on the OS level so there’s no way for you to see that in the DOM or use Selenium to interact with it. If you really need to deal with it, I’d suggest you look into an OS-level automation tool that could send key or mouse events to handle the dialog in a way you need to.

With Java, you would be fine using the Robot class defined in the Java AWT package, as it’s meant exactly for dealing with native input events associated with test automation and is often referred to when dealing with Selenium and dialogs. However, it doesn’t exist in the .NET world so you need to look elsewhere. A quick Google search gave me something that might help:

Robot Framework (Supports .NET by using IronPython)

Also, you could do it even simpler with something like this:


So, to summarize. No, it’s not a normal Alert as you expect it to be and yes, you can handle it but it requires some steps outside the Selenium world.

Answered By – Timo Salomäki

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published