AmitS
AmitS

Reputation: 5

How to identify that browser alert box is present on page or not by using selenium C#

I am facing a issue while automating the script through selenium C#

I have a scenario in which a browser popup is displayed on the page after clicking a link.

I have to identify that on clicking the desired link whether the browser alert displayed or not.???

I need something like Is alert present ?????

Upvotes: 0

Views: 745

Answers (1)

sevine
sevine

Reputation: 36

Simply try to accept the alert using try-catch: if alert accepted - step is passed, else - failed

if you need a method try the next (checking alert present):

public bool isAlertPresent() 
{ 
    try 
    { 
        driver.switchTo().alert(); 
        return true; 
    }
    catch (NoAlertPresentException Ex) 
    { 
        return false; 
    }
}

Upvotes: 1

Related Questions