package com.selenium.gen;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
public class Alert {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
ChromeOptions options=new ChromeOptions();
//您使用的是不受支持的命令行标记:--ignore-certificate-errors。稳定性和安全性会有所下降,设置
options.addArguments("--start-maximized", "allow-running-insecure-content", "--test-type");
// options.addArguments("--user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
ChromeDriver driver=new ChromeDriver(options);
//打开浏览器
driver.get("https://www.baidu.com");
//浏览器最大化
driver.manage().window().maximize();
//鼠标单击并悬停
Actions action = new Actions(driver);
action.clickAndHold(driver.findElement(By.linkText("设置"))).perform();
//释放鼠标
action.release();
//点击搜索设置
action.moveToElement(driver.findElement(By.className("setpref"))).click().perform();
Thread.sleep(2000);
//点击保存设置
driver.findElement(By.className("prefpanelgo")).click();
Thread.sleep(2000);
//接受弹框
driver.switchTo().alert().accept();
//关闭浏览器
driver.close();
}
}