Alert doesn't close using Selenium WebDriver with Google Chrome.

前端 未结 2 1316
-上瘾入骨i
-上瘾入骨i 2021-01-24 15:16

I have the following Selenium script for opening alert on rediff.com:

public class TestC {
    public static void main(S         


        
2条回答
  •  旧时难觅i
    2021-01-24 16:09

    Unfortunately AlertIsPresent doesn't exist in C# API http://selenium.googlecode.com/git/docs/api/dotnet/index.html

    You can use something like this:

    private static bool TryToAcceptAlert(this IWebDriver driver)
    {
        try
        {
            var alert = driver.SwitchTo().Alert();
            alert.Accept();
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
    
    
    public static void AcceptAlert(this IWebDriver driver, int timeOutInSeconds = ElementTimeout)
    {
        new WebDriverWait(driver, TimeSpan.FromSeconds(timeOutInSeconds)).Until(
            delegate { return driver.TryToAcceptAlert(); }
            );
    }
    

提交回复
热议问题