如何处理硒中 SafariDriver 的警报?
How to handle alert for SafariDriver in selenium?
请帮我处理 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();
}
}
您需要explicitly wait for the alert to appear:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
请帮我处理 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();
}
}
您需要explicitly wait for the alert to appear:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();