Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:06:43+00:00 2026-05-30T10:06:43+00:00

It seems that in the ASP.NET WebDriver API, executing the following when there is

  • 0

It seems that in the ASP.NET WebDriver API, executing the following when there is no javascript alert present results in an exception:

browser.SwitchTo().Alert();

IE and FF both throw a WebDriverException, but Chrome throws an InvalidOperationException.

So far, this is the only code that seems to work:

try
{
    var alert = browser.SwitchTo().Alert();
    if (alert != null)
        alert.Dismiss();
}
catch (WebDriverException)
{
    // alert was not present in IE or FF
}
catch (InvalidOperationException)
{
    // alert was not present in Chrome
}

Is there a way to check that an alert dialog is present, without having to catch an exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:06:44+00:00Added an answer on May 30, 2026 at 10:06 am

    The actual answer here is no, you must always catch an exception. The logic behind the design of the API is that you should always be aware of what browser state you expect. If you expect an alert to appear, you should be able to use switchTo() to switch to it and handle it. If you expect an alert to appear, and use switchTo() and it is not present, that is an exceptional condition, and an exception is thrown. The normal (non-exceptional) case is to not expect an alert, and thus there is no corresponding method to look for an alert not being displayed. Incidentally, this is the same logic employed by findElement(). You can argue that the wrong logic is being employed by the API designers, but that is the way the current API is implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it seems that I just solved my problem why I couldn't use the ASP.NET
How ASP.NET compiles its assemblies generally confuses me. It seems that I cannot program
I'm learning ASP.NET MVC Framework, From some articles like this , it seems that
It seems that ASP.NET MVC just runs on top of ASP.NET WebForms. System.Web.Mvc.ViewPage in
It seems that the default ASP.NET MVC2 Html helper generates duplicate HTML IDs when
I have built an ASP.NET mvc web application and it seems that some of
In VS2010 and ASP.NET MVC 2, it seems that client-side validation (JQuery Futures or
It seems that when adding a row to an ASP.NET GridView, the Tab Index
I'm trying to use an UpdatePanel in my ASP.NET application. Unfortunately, it seems that
It seems to me that ASP.net queues up all requests that use the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.