简体   繁体   English

如何处理硒中SafariDriver的警报?

[英]How to handle alert for SafariDriver in selenium?

Please Help me handle alert in safari 请帮我处理野生动物园的警报

The result that I get in this following is that safari cannot handle alert so is there any other method to handle the alert 我在以下内容中得到的结果是,野生动物园无法处理警报,因此还有其他方法可以处理警报

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();
    }

}

You need to explicitly wait for the alert to appear : 您需要明确等待警报出现

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM