How do you handle alert pop-up ?
Ans- To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle then move control back to main page.
String mainPage = driver.getWindowHandle();
Alert alt = driver.switchTo().alert(); // to move control to alert popup
alt.accept(); // to click on ok.
alt.dismiss(); // to click on cancel.
//Then move the control back to main web page-
driver.switchTo().window(mainPage); → to switch back to main page.
|
No comments:
Post a Comment