Showing posts with label alerts. Show all posts
Showing posts with label alerts. Show all posts
Saturday, April 22, 2017
Friday, April 21, 2017
Saturday, April 8, 2017
How to identify and close window alert using selenium
At times in browser,Alert box with a specified message and an OK button is displayed to ensure information comes through to the user.
Alert box prevents the user from accessing other parts of the page until the box is closed. An alert is displayed is as shown below:
While automating the web application, we can handle the pop up using alert Interface
The alert() method displays an alert box with a specified message and an OK button.
Below code shows how to close an window alert pop up using selenium:
The alert() method displays an alert box with a specified message and an OK button.
Below code shows how to close an window alert pop up using selenium:
public void Accept_Alert_Message() {
try {
//Using webdriver wait, we will wait for the alert
//to appear before performing action on the alert
WebDriverWait driverwait = new WebDriverWait(driver, 5);
driverwait.until(ExpectedConditions.alertIsPresent());
//switch to the alert element
Alert alert = driver.switchTo().alert();
//accept the alert displayed
alert.accept();
//switch to the default content
driver.switchTo().defaultContent();
} catch (Exception e) {
// in case alert is not displayed, the code will go to catch loop
}
}
Sunday, September 25, 2016
Switching to frame, Windows, alert in Selenium WebDriver
1. How to Switch from one frame to another
// How to Switch from one frame to another
WebElement iFrmeElement = driver.findElement(By.xpath("xPath for Frame"));
driver.switchTo().frame(frameElement);
//Or
driver.switchTo().frame(id or name)
//Or
driver.switchTo().frame(index of frame)
2. We can switch to default again by:
driver.switchTo().defaultContent();
3. We can switch to a window based on name, Id or Windows handle
driver.switchTo().window("windowName");
4. We can switch to an alert
Alert alert = driver.switchTo().alert();
// We can close an alert using methods for alert object
alert. accept();
Subscribe to:
Posts (Atom)