How to handle a JavaScript pop-up with C#- NUnit?

How to handle a JavaScript pop-up with C#- NUnit?

Hey Rhian,

To handle a JavaScript pop-up with C#- NUnit, you can refer to the sample code snippet below:

   //Initialize your wait.
    WebDriverWait wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(5));
    //Wait for alert
    try
    {
        wait.Until(ExpectedConditions.AlertIsPresent());    
        if (accept)
        {
            Driver().Instance.SwitchTo().Alert().Accept();
        }
        else
        {
            Driver().Instance.SwitchTo().Alert().Dismiss();
        }    
    }
    catch (WebDriverTimeoutException) { /*Alert did not appear, do nothing*/ }
}