Selenium WebDriver - How do you handle alert pop-up ?
Selenium WebDriver Interview question and Answers
(Continued from previous question...)
Selenium WebDriver - How do you handle alert pop-up ?
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.
Syntax-
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.
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.
(Continued on next question...)
Other Interview Questions
|