有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

请帮我处理safari中的警报

我在下面得到的结果是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) 个答案

  1. # 1 楼答案

    您需要执行以下操作:

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