alert彈窗 confirm彈窗 prompt彈窗
- 點擊確定
// 選取警告彈窗
Alert alert=driver.switchTo().alert();
// 點擊取消按鈕
alert.accept();
- 點擊取消
// 選取警告彈窗
Alert alert=driver.switchTo().alert();
// 輸出彈窗內容getText()
System. out .println(driver.switchTo().alert().getText());
// 點擊取消按鈕
alert.dismiss();
- 輸入內容
// 選取警告彈窗
Alert prompt=driver.switchTo().alert();
// 輸出彈窗內容
prompt.sendKeys( "輸入值" );
// 點擊確定按鈕
prompt.accept();