如何在selenium中处理SafariDriver的警报?

时间:2015-04-06 12:26:18

标签: java macos selenium selenium-ide

请帮我处理野生动物园的警报

我在下面得到的结果是safari无法处理警报,所以还有其他任何方法来处理警报

package Default;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;

public class Safari_demo {

    public static void main(String[] args) throws InterruptedException{

        WebDriver driver = new SafariDriver();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get("http://www.htmlite.com/JS002.php");

        Thread.sleep(6000);

        Alert alert = driver.switchTo().alert();
        alert.accept();

        driver.close();
    }

}

1 个答案:

答案 0 :(得分:1)

您需要 explicitly wait for the alert to appear

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.alertIsPresent());

Alert alert = driver.switchTo().alert();