Alert方法
在某些特殊场景会有弹窗展示,这个时候我们可以使用Alter方法去处理它
应用:
package com.ming.Selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Alert {
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://news.cyol.com/node_60799.htm");
Thread.sleep(3000);
// 处理alert框
System.out.println(driver.switchTo().alert().getText());
driver.switchTo().alert().accept();
}
}
Alert还有以下方法
public interface Alert {
void dismiss(); //取消
void accept(); //接受
String getText();//获取内容
void sendKeys(String keysToSend);//输入内容
}