3
我需要阅读警报&弹出窗口中使用java显示的确认消息,并将其打印在控制台上。在硒记录从IDE导出为Junit4(webdriver的)的java文件,我的代码是:如何使用Firefox驱动程序读取警报消息?
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
现在,当我试图用getAlert
或getConfirmation
功能如下所示:
@Test
public void testSample() throws Exception {
Alert alert = driver.switchTo().alert();
message = alert.getText();
System.out.println("message is "+message);
}
我得到以下错误:
java.lang.NullPointerException
at com.example.tests.Sample.testSample(Sample.java:40)
at com.example.tests.Sample.main(Sample.java:149)
Exception: null
如何处理呢?还有没有其他的方式来阅读弹出消息?